Are `switch` statements over `String` ever optimized to a hash table lookup?

Check out StringSwitch.swift, specifically _findStringSwitchCaseWithCache. The cache is a Dictionary, so it's a hash-table lookup, but it only appears to apply to strings.

It gets used in SILOptimizer: swift/ObjectOutliner.cpp at 291364b2f1b81c100b155de900494780ed79bded 路 apple/swift 路 GitHub

EDIT: It's only used for synthesised RawRepresentable conformances. There is a PR to expand this.

1 Like