diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-01-02 21:12:58 +0000 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-01-02 21:12:58 +0000 |
commit | 5b7139aab41becad7ad736bd9ff2332960bf67f9 (patch) | |
tree | 9d3d3e7da0c0073af1fd2784fa7892d3222f9e88 /Objects/stringlib/partition.h | |
parent | d3e323215c6d9f303bf42875f98e365e2ff1734f (diff) | |
download | cpython-git-5b7139aab41becad7ad736bd9ff2332960bf67f9.tar.gz |
Issue #7462: Implement the stringlib fast search algorithm for the `rfind`,
`rindex`, `rsplit` and `rpartition` methods. Patch by Florent Xicluna.
Diffstat (limited to 'Objects/stringlib/partition.h')
-rw-r--r-- | Objects/stringlib/partition.h | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/Objects/stringlib/partition.h b/Objects/stringlib/partition.h index 105ba317d6..2f26212983 100644 --- a/Objects/stringlib/partition.h +++ b/Objects/stringlib/partition.h @@ -58,7 +58,7 @@ stringlib_rpartition( ) { PyObject* out; - Py_ssize_t pos, j; + Py_ssize_t pos; if (sep_len == 0) { PyErr_SetString(PyExc_ValueError, "empty separator"); @@ -69,20 +69,14 @@ stringlib_rpartition( if (!out) return NULL; - /* XXX - create reversefastsearch helper! */ - pos = -1; - for (j = str_len - sep_len; j >= 0; --j) - if (STRINGLIB_CMP(str+j, sep, sep_len) == 0) { - pos = j; - break; - } + pos = fastsearch(str, str_len, sep, sep_len, FAST_RSEARCH); if (pos < 0) { Py_INCREF(STRINGLIB_EMPTY); PyTuple_SET_ITEM(out, 0, (PyObject*) STRINGLIB_EMPTY); Py_INCREF(STRINGLIB_EMPTY); PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY); - Py_INCREF(str_obj); + Py_INCREF(str_obj); PyTuple_SET_ITEM(out, 2, (PyObject*) str_obj); return out; } |