Hacker News new | ask | show | jobs
by est 4948 days ago
because counting 2 bytes is much faster for computers than counting vary 1, 2, 3 or even 4 bytes.
1 comments

This is not a real issue because counting code points in an UTF8 string is easy too: the encoding is cleverly defined such that you just need to check the number of bytes that have the top bit cleared. Since UTF8 strings are generally shorter it can even be faster than counting UTF-16 if you don't know the length in advance.