4 ms·
> The Python problem is amusing. Python 3 has three representations of strings internally (1-byte, 2-byte, and 4-byte) and promotes them to a wider form when ne
by the_mitsuhiko 10y ago
> The Python problem is amusing. Python 3 has three representations of strings internally (1-byte, 2-byte, and 4-byte) and promotes them to a wider form when necessary. This is mostly to support string indexing. It probably would have been better to use UTF-8, and create an index array for the string when necessary.
It's especially amusing because on Python 3 strings internally cache their utf-8 equivalent if it was used once.
- Animats 10y agoI didn't know that. That's funny. They really are doing this the hard way.
- int_19h 10y agoIt really is the hard way. For the curious, read through the comment here describing the data layout and invariants: https://github.com/python/cpython/blob/master/Include/unicodeobject.h#L213 https://github.com/python/cpython/blob/master/Include/unicod...