[Python-checkins] r46425 - python/trunk/Objects/stringobject.c
andrew.dalke
python-checkins at python.org
Sat May 27 00:49:03 CEST 2006
Author: andrew.dalke
Date: Sat May 27 00:49:03 2006
New Revision: 46425
Modified:
python/trunk/Objects/stringobject.c
Log:
Added description of why splitlines doesn't use the prealloc strategy
Modified: python/trunk/Objects/stringobject.c
==============================================================================
--- python/trunk/Objects/stringobject.c (original)
+++ python/trunk/Objects/stringobject.c Sat May 27 00:49:03 2006
@@ -3768,6 +3768,14 @@
data = PyString_AS_STRING(self);
len = PyString_GET_SIZE(self);
+ /* This does not use the preallocated list because splitlines is
+ usually run with hundreds of newlines. The overhead of
+ switching between PyList_SET_ITEM and append causes about a
+ 2-3% slowdown for that common case. A smarter implementation
+ could move the if check out, so the SET_ITEMs are done first
+ and the appends only done when the prealloc buffer is full.
+ That's too much work for little gain.*/
+
list = PyList_New(0);
if (!list)
goto onError;
More information about the Python-checkins
mailing list