mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
Merged revisions 77241 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r77241 | antoine.pitrou | 2010-01-02 22:12:58 +0100 (sam., 02 janv. 2010) | 4 lines 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:
parent
2952148dd2
commit
da2ecaf334
10 changed files with 131 additions and 115 deletions
|
|
@ -32,20 +32,19 @@ stringlib_rfind(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
|||
const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
|
||||
Py_ssize_t offset)
|
||||
{
|
||||
/* XXX - create reversefastsearch helper! */
|
||||
if (sub_len == 0) {
|
||||
if (str_len < 0)
|
||||
return -1;
|
||||
return str_len + offset;
|
||||
} else {
|
||||
Py_ssize_t j, pos = -1;
|
||||
for (j = str_len - sub_len; j >= 0; --j)
|
||||
if (STRINGLIB_CMP(str+j, sub, sub_len) == 0) {
|
||||
pos = j + offset;
|
||||
break;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
Py_ssize_t pos;
|
||||
|
||||
if (str_len < 0)
|
||||
return -1;
|
||||
if (sub_len == 0)
|
||||
return str_len + offset;
|
||||
|
||||
pos = fastsearch(str, str_len, sub, sub_len, FAST_RSEARCH);
|
||||
|
||||
if (pos >= 0)
|
||||
pos += offset;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
Py_LOCAL_INLINE(Py_ssize_t)
|
||||
|
|
@ -64,10 +63,7 @@ stringlib_find_slice(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
|||
if (end < 0)
|
||||
end = 0;
|
||||
|
||||
return stringlib_find(
|
||||
str + start, end - start,
|
||||
sub, sub_len, start
|
||||
);
|
||||
return stringlib_find(str + start, end - start, sub, sub_len, start);
|
||||
}
|
||||
|
||||
Py_LOCAL_INLINE(Py_ssize_t)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue