summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Dalke <dalke@dalkescientific.com>2006-05-26 22:49:03 (GMT)
committerAndrew Dalke <dalke@dalkescientific.com>2006-05-26 22:49:03 (GMT)
commit7e0a62ea9052faf0e19dc2438124751b8f68ce16 (patch)
tree71aed0fd398e7f7e37b8edad8728f8404e4e4522
parent57ad0607223d65472e7beb63e353224d8a901fac (diff)
downloadcpython-7e0a62ea9052faf0e19dc2438124751b8f68ce16.zip
cpython-7e0a62ea9052faf0e19dc2438124751b8f68ce16.tar.gz
cpython-7e0a62ea9052faf0e19dc2438124751b8f68ce16.tar.bz2
Added description of why splitlines doesn't use the prealloc strategy
-rw-r--r--Objects/stringobject.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index c59c74e..7e93783 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -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;