[Python-Dev] Replacement for array.array('u')? (original) (raw)
Serhiy Storchaka storchaka at gmail.com
Fri Mar 22 07:31:48 EDT 2019
- Previous message (by thread): [Python-Dev] Replacement for array.array('u')?
- Next message (by thread): [Python-Dev] Replacement for array.array('u')?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
22.03.19 09:45, Victor Stinner пише:
Internally, CPython has a PyUnicodeWriter which is an efficient way to create a string but appending substrings or characters. PyUnicodeWriter changes the internal storage format depending on characters code points (ascii or latin1: 1 byte/character, BMP: 2 b/c, full UCS: 4 b/c). I tried once to expose it in Python, but I wasn't convinced by performances. The overhead of method calls was quite significant, and I wasn't convinced by "writer += str" performance neither. Maybe I should try again. PyPy also has such object. It avoids the "str += str" hack in ceval.c to avoid very poor performance (PyUnicodeWriter also uses overallocation which can be controlled with multiple parameters to reduce the number of realloc).
Another alternative would be have to add a "strarray" type similar to bytes/bytearray couple.
Another alternative of mutable string buffer and string builder is io.StringIO.
- Previous message (by thread): [Python-Dev] Replacement for array.array('u')?
- Next message (by thread): [Python-Dev] Replacement for array.array('u')?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]