diff options
author | Fredrik Lundh <fredrik@pythonware.com> | 2006-05-25 19:19:05 (GMT) |
---|---|---|
committer | Fredrik Lundh <fredrik@pythonware.com> | 2006-05-25 19:19:05 (GMT) |
commit | 554da412a8c0b62d62babd9fd2f63645b46369fe (patch) | |
tree | d10213d4ce34adf4f47f86960792498640394812 /Objects | |
parent | 684fd0c8ec0bad54d3ff39ae15873f80e119478b (diff) | |
download | cpython-554da412a8c0b62d62babd9fd2f63645b46369fe.zip cpython-554da412a8c0b62d62babd9fd2f63645b46369fe.tar.gz cpython-554da412a8c0b62d62babd9fd2f63645b46369fe.tar.bz2 |
needforspeed: use insert+reverse instead of append
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/stringobject.c | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 402de12..560e30f 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -1461,18 +1461,6 @@ static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"}; else \ Py_DECREF(str); -#define SPLIT_INSERT(data, left, right) \ - str = PyString_FromStringAndSize((data) + (left), \ - (right) - (left)); \ - if (str == NULL) \ - goto onError; \ - if (PyList_Insert(list, 0, str)) { \ - Py_DECREF(str); \ - goto onError; \ - } \ - else \ - Py_DECREF(str); - static PyObject * split_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxsplit) { @@ -1632,15 +1620,17 @@ rsplit_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxsplit) if (j > i) { if (maxsplit-- <= 0) break; - SPLIT_INSERT(s, i + 1, j + 1); + SPLIT_APPEND(s, i + 1, j + 1); while (i >= 0 && isspace(Py_CHARMASK(s[i]))) i--; j = i; } } if (j >= 0) { - SPLIT_INSERT(s, 0, j + 1); + SPLIT_APPEND(s, 0, j + 1); } + if (PyList_Reverse(list) < 0) + goto onError; return list; onError: Py_DECREF(list); @@ -1661,14 +1651,16 @@ rsplit_char(const char *s, Py_ssize_t len, char ch, Py_ssize_t maxcount) if (s[i] == ch) { if (maxcount-- <= 0) break; - SPLIT_INSERT(s, i + 1, j + 1); + SPLIT_APPEND(s, i + 1, j + 1); j = i = i - 1; } else i--; } if (j >= -1) { - SPLIT_INSERT(s, 0, j + 1); + SPLIT_APPEND(s, 0, j + 1); } + if (PyList_Reverse(list) < 0) + goto onError; return list; onError: |