]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Added description of why splitlines doesn't use the prealloc strategy
authorAndrew Dalke <dalke@dalkescientific.com>
Fri, 26 May 2006 22:49:03 +0000 (22:49 +0000)
committerAndrew Dalke <dalke@dalkescientific.com>
Fri, 26 May 2006 22:49:03 +0000 (22:49 +0000)
Objects/stringobject.c

index c59c74ed05e97b58e6e0f06883fa8c4f92f5623e..7e9378394b9c07d36790ed0ded3f06307d8a079f 100644 (file)
@@ -3768,6 +3768,14 @@ string_splitlines(PyStringObject *self, PyObject *args)
     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;