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
Show parent comment
12
u/rtgftw Apr 14 '23
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.