Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It is, but it's not worth wasting 4x memory for the common case of mostly-Latin text.

It also turns out that you very rarely need arbitrary string indexing. Most of the time, when you're indexing into a string, it's a fixed (and relatively small) number of bytes from the start or end. UTF-8 can do this in a tight inner loop that just checks for bytes that don't start with 0b10. If you need .startswith or .endswith, you can just compare bytes with a byte length offset. If you need to do substring search, you can do Boyer-Moore on bytes. If you need to test for equality, do it on bytes. If you need to chop a string in half for divide & conquer algorithms and only need to be approximately right, you can chop in half by bytes and then use UTF-8's self-synchronizing property to find the nearest character boundary.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: