summaryrefslogtreecommitdiffstats
path: root/Objects/stringlib/find.h
diff options
context:
space:
mode:
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 fbe99c7..b5bace7 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)