3 ms·
While a neat trick, there are some caveats. First of all, the is_ascii_branchless can be written in c++ as return std::all_of(sv.begin(),sv.end(),[](uint8_
by RcouF1uZ4gsC 6y ago
While a neat trick, there are some caveats. First of all, the is_ascii_branchless can be written in c++ as
return std::all_of(sv.begin(),sv.end(),[](uint8_t c){return c < 128;});
Once you do that, the differences in code complexity between this and the other solutions becomes even more stark.
Second, even the slow case is 2 GB/s. While the principle is helpful, the extra complexity may not be worth it in the vast majority of real life code.
- P-ala-din 6y agoA thing I want to stress, is that you pay for the "complexity" just once, and it gets amortized over all projects that use this code. This is a standard technique, that is often used in String functions. You can see it also in implementations of strlen.