summaryrefslogtreecommitdiffstats
path: root/Objects/stringlib/find.h
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-01-02 21:40:36 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-01-02 21:40:36 (GMT)
commitda2ecaf3349d564ef0392183d86270eea5cdb439 (patch)
treed30ed807e0e325a492f999576bf19fd370b0dbda /Objects/stringlib/find.h
parent2952148dd246b67ca88a68c44819a208d0d6624a (diff)
downloadcpython-da2ecaf3349d564ef0392183d86270eea5cdb439.zip
cpython-da2ecaf3349d564ef0392183d86270eea5cdb439.tar.gz
cpython-da2ecaf3349d564ef0392183d86270eea5cdb439.tar.bz2
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. ........
Diffstat (limited to 'Objects/stringlib/find.h')
-rw-r--r--Objects/stringlib/find.h32
1 files changed, 14 insertions, 18 deletions
diff --git a/Objects/stringlib/find.h b/Objects/stringlib/find.h
index bf06530..bf27d6a 100644
--- a/Objects/stringlib/find.h
+++ b/Objects/stringlib/find.h
@@ -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)