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 _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com