News for hackers. Stuff that matters.
Re:Avoid character-by-character processing when performance ... by galkk on Saturday July 25, 2020 @03:17AM (#23947410)
Exactly that, I was surprised to see that looong for loop definition (I'm not using C++ at all) and wanted to see if there's anything else to simplify. First I found for_each then all_of

If anyone is interested, here is simpler version:

    bool is_ascii_branchy(const std::string_view v) {
        return std::all_of(v.begin(), v.end(), [](auto i) { 
    return uint8_t(i) < 128;});
    }
Re:Avoid character-by-character processing when performance ... by jonstewart on Saturday July 25, 2020 @09:06AM (#23948890)
STL is great! How’s the performance, though, compared with TFA’s optimistic and hybrid versions?
Re:Avoid character-by-character processing when performance ... by cornstalks on Saturday July 25, 2020 @10:16AM (#23949328)
And for a fair comparison, here's an imperative loop that's way cleaner than what TFA used:

    bool is_ascii_branchy(std::string_view v) {
        for (auto c : v) if (uint8_t(c) < 128) return false;
        return true;
    }
Re:Avoid character-by-character processing when performance ... by im3w1l on Saturday July 25, 2020 @05:58AM (#23947957)
So I guess this would be the best way to write it if you have a set of long strings most of which are non-ascii, and most such strings having a high proportion of non-ascii? Since then early exit will really help.