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

Victor Stinner victor.stinner at haypocalc.com
Mon Oct 3 04:19:53 CEST 2011


Le dimanche 2 octobre 2011 15:25:21, Antoine Pitrou a écrit :
> 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".

Oh, I see. In Python 2.7, bytes+=bytes calls PyMem_Realloc() on then writes 
the new characters to the result. It doesn't overallocate as bytearray (which 
overallocate +12,5%).

I restored this hack in Python 3.3 using PyUnicode_Append() in ceval.c and by 
optimizing PyUnicode_Append() (try to append in-place). str+=str is closer 
again to ''.join:

str += str: 696 ms
''.join():  547 ms

I disabled temporary the optimization for wstr string in PyUnicode_Resize() 
because of a bug. I disabled completly resize on Windows because of another 
bug.

Victor


More information about the Python-Dev mailing list