3 ms·
For swift and maybe other languages that have the small string optimisation the compiler is able to do comparisons using a similar mask and comparison. I’m surp
by benmmurphy 4y ago
For swift and maybe other languages that have the small string optimisation the compiler is able to do comparisons using a similar mask and comparison. I’m surprised the default c++ benchmark didn’t benefit from this but maybe the standard library doesn’t use the small string optimisation.
- moloch-hai 4y agoIt does, but these are not strings.
- benmmurphy 4y agoI tried it using String instead of StringView and it didn't do the comparison optimisation either. For GCC it did inline one of the comparisons (https://godbolt.org/z/G3Ydfoxqc https://godbolt.org/z/G3Ydfoxqc). Probably, its not possible to do the optimisation with the standard library because the standard library doesn't guarantee that small strings will be in small string form so you always have to fallback on failure. Also, it doesn't work for swift because swift string comparison is based on some kind of normalisation. So there is a fast path check using the small string optimisation but if that fails it falls back to a slow check that tries to do normalisation. (https://swift.godbolt.org/z/fscsarGjb https://swift.godbolt.org/z/fscsarGjb)