Mercurial > cpython-lru_cache-weakref
diff Objects/stringobject.c @ 38315:91c6c94490b1 legacy-trunk
needforspeed: use insert+reverse instead of append
| author | Fredrik Lundh <fredrik@pythonware.com> |
|---|---|
| date | Thu, 25 May 2006 19:19:05 +0000 |
| parents | c9dc300eee68 |
| children | ea0ad4d4ff8e |
line wrap: on
line diff
--- a/Objects/stringobject.c Thu May 25 19:15:31 2006 +0000 +++ b/Objects/stringobject.c Thu May 25 19:19:05 2006 +0000 @@ -1461,18 +1461,6 @@ 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 @@ 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 @@ 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:
