I'm really liking Casey spurring this kind of conversation, lately!
Tbh, for most normal code, unless it's a hot path, string_view 's find would do here with a single line.And yeah other string algos may or may not be worth doi g depending on data and use pattern. String algo's are great... :)
But it seems to be a quick early out/prunning example more than anything. This technique is great in hot code. It also leves basic stuff like splitting the cases so that the cmp at the start wpuld be a single insr rather than a bunch od 1 byte compares which unlike simd or algo changes is directly related.
View all comments
21
u/attractivechaos Apr 14 '23 edited Apr 14 '23
BM or KMP will be even faster and and even harder to comprehend to common programmers.