3 ms·
This doesn't seem insurmountable. Three steps: 1. Introduce new methods which allow access to code points without indexing by UCS-2 code unit. An iterator over
by twic 9y ago
This doesn't seem insurmountable. Three steps:
1. Introduce new methods which allow access to code points without indexing by UCS-2 code unit. An iterator over code points is the key thing. You could also have some opaque kind of index, with a method to get a list of indices for every code point in the string, and then a method to look up a code point by opaque index. The former could be expensive, as it would involve scanning the string to find where each character starts (although perhaps that could be done lazily?), but the latter should be cheap. The results of the expensive method could be cached.
2. Wait N years for the new methods to be widely adopted.
3. Shift the internal representation of strings to UTF-8. Anyone using the new methods will see similar, or better, performance. Anyone using the old methods will see a drop in performance. Implementations could even dynamically choose between representations based on usage patterns. The fact that each web page is its own little JS universe should make that fairly practical.