On Mar 30, 2020, at 10:18, Joao S. O. Bueno <[email protected]> wrote:
>
> That said, anyone could tell about small, efficient,
> well maintained "mutable string" classes on Pypi?
I don’t know of one. But what do you actually want it for? In most cases where
you want “mutable strings”, what you really want is either a string builder
(just wrap up a list of strings and join), or something that (unlike a list,
array.array, etc.) provides insert and delete of substrings in better than
linear time, like a gap buffer or rope or tree-indexed thing or similar (and
there are good PyPI libraries for some of those things). But if you actually
have a use for a simple mutable string that had the str API plus the
MutableSequence API and performs roughly like array.array('Q') but with
substrings instead of their codepoint int values, I don’t think anyone’s built
that.
If you want to build it yourself, I doubt it’s possible to make a pure-Python
version that’s efficient enough for real use in CPython; you’d probably need a
C accelerator just to avoid the cost of boxing and unboxing between ints and
single-char strings for most operations. However, you probably could build a
minimal “ucs4array” class with a C accelerator and then build most of the str
API on top of that in pure Python. (Or, if you want the space efficiency of
CPython strings, you need ucs1/ucs2/ucs4array types and a str that switches
between them.)
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/Z7MCYC3P3A6T2X67TO6XZA7LINIXDS7W/
Code of Conduct: http://python.org/psf/codeofconduct/