News for hackers. Stuff that matters.
Re:Avoid character-by-character processing when performance ... by RcouF1uZ4gsC on Saturday July 25, 2020 @03:10AM (#23947378)
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.

Re:Avoid character-by-character processing when performance ... by P-ala-din on Saturday July 25, 2020 @07:20AM (#23948353)
A 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.