News for hackers. Stuff that matters.
Re:The History and rationale of the Python 3 Unicode model f... by Animats on Wednesday December 14, 2022 @02:53PM (#33989258)
Unicode string indexing should have been made lazy, rather than deprecated. Random access to strings is rare. Mostly, operations are moving forward linearly or using saved positions.

So, only build the index for random access if needed. Optimize "advance one glyph" and "back up one glyph" expressed as indexing, and you'll get most of the frequently used cases. Have the "index" functions that return a string index return an opaque type that's a byte index. Attempting to convert that to an integer forces creation of the string index.

This preserves the user visible semantics but keeps performance.

PyPy does something like this.

There are no comments on this comment yet.