Issue #7462: Implement the stringlib fast search algorithm for the rfind,

`rindex`, `rsplit` and `rpartition` methods.  Patch by Florent Xicluna.
This commit is contained in:
Antoine Pitrou 2010-01-02 21:12:58 +00:00
parent d3e323215c
commit 5b7139aab4
11 changed files with 148 additions and 149 deletions

View file

@ -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;
}