3 ms·
Yep, assuming the byte sequence is guaranteed to be valid UTF-8 in any case. But if there's a chance that it isn't, then it's probably coming from disk, network
by pmjordan 18y ago
Yep, assuming the byte sequence is guaranteed to be valid UTF-8 in any case. But if there's a chance that it isn't, then it's probably coming from disk, network, etc., so the IO will outweigh the extra validation anyway.
Back-iterating works pretty well, too.
Indexed code point access is the only thing that has a real penalty, as it is always O(n) in time unless you add an O(n) memory position table with O(n) preprocessing time and O(1) runtime lookup. However, code point access only gives you so much anyway, as combining code points mean you can have more than one code point per character. You have that same problem with UTF-32.