[Python-Dev] RFC: Add a new builtin strarray type to Python?

Antoine Pitrou solipsis at pitrou.net
Sun Oct 2 15:25:21 CEST 2011


On Sun, 2 Oct 2011 15:00:01 +0200
Victor Stinner <victor.stinner at haypocalc.com> wrote:
> 
> > I don't understand why StringIO couldn't simply be optimized a little
> > more, if it needs to.
> 
> Honestly, I didn't know that StringIO.write() is more efficient than str+=str, 
> and it is surprising to use the io module (which is supposed to be related to 
> files) to manipulate strings.

StringIO is an in-memory file-like object, like in 2.x (where it lived
in the "cStringIO" module). I don't think it's a novel thing.

> The PEP 393 uses one memory block, you cannot resize a str object anymore.

I don't know why you're saying that. The concatenation optimization
worked in 2.x where the "str" type also used only one memory block. You
just have to check that the refcount is about to drop to zero.
Of course, resizing only works if the two unicode objects are of the
same "kind".

Regards

Antoine.




More information about the Python-Dev mailing list