diff options
author | Fredrik Lundh <fredrik@pythonware.com> | 2006-05-27 15:26:19 (GMT) |
---|---|---|
committer | Fredrik Lundh <fredrik@pythonware.com> | 2006-05-27 15:26:19 (GMT) |
commit | 0b7ef46950e383aaac7eeed1dff2c622d144fffe (patch) | |
tree | e28f785499d0619a721560389174c2f4eb47ddf2 /Objects | |
parent | 60d8b1883113b35fa72e94dbf58e2e439120a1ae (diff) | |
download | cpython-0b7ef46950e383aaac7eeed1dff2c622d144fffe.zip cpython-0b7ef46950e383aaac7eeed1dff2c622d144fffe.tar.gz cpython-0b7ef46950e383aaac7eeed1dff2c622d144fffe.tar.bz2 |
needforspeed: stringlib refactoring: use find_slice for stringobject
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/stringobject.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 7eab4bd..6108c39 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -1846,32 +1846,35 @@ string_adjust_indices(Py_ssize_t *start, Py_ssize_t *end, Py_ssize_t len) Py_LOCAL_INLINE(Py_ssize_t) string_find_internal(PyStringObject *self, PyObject *args, int dir) { - const char *s = PyString_AS_STRING(self), *sub; - Py_ssize_t len = PyString_GET_SIZE(self); - Py_ssize_t n, i = 0, last = PY_SSIZE_T_MAX; PyObject *subobj; + const char *sub; + Py_ssize_t sub_len; + Py_ssize_t start=0, end=PY_SSIZE_T_MAX; /* XXX ssize_t i */ - if (!PyArg_ParseTuple(args, "O|O&O&:find/rfind/index/rindex", - &subobj, _PyEval_SliceIndex, &i, _PyEval_SliceIndex, &last)) + if (!PyArg_ParseTuple(args, "O|O&O&:find/rfind/index/rindex", &subobj, + _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) return -2; if (PyString_Check(subobj)) { sub = PyString_AS_STRING(subobj); - n = PyString_GET_SIZE(subobj); + sub_len = PyString_GET_SIZE(subobj); } #ifdef Py_USING_UNICODE else if (PyUnicode_Check(subobj)) - return PyUnicode_Find((PyObject *)self, subobj, i, last, dir); + return PyUnicode_Find( + (PyObject *)self, subobj, start, end, dir); #endif - else if (PyObject_AsCharBuffer(subobj, &sub, &n)) + else if (PyObject_AsCharBuffer(subobj, &sub, &sub_len)) return -2; - string_adjust_indices(&i, &last, len); - if (dir > 0) - return stringlib_find(s+i, last-i, sub, n, i); + return stringlib_find_slice( + PyString_AS_STRING(self), PyString_GET_SIZE(self), + sub, sub_len, start, end); else - return stringlib_rfind(s+i, last-i, sub, n, i); + return stringlib_rfind_slice( + PyString_AS_STRING(self), PyString_GET_SIZE(self), + sub, sub_len, start, end); } |