diff options
author | Fredrik Lundh <fredrik@pythonware.com> | 2006-05-26 19:48:07 (GMT) |
---|---|---|
committer | Fredrik Lundh <fredrik@pythonware.com> | 2006-05-26 19:48:07 (GMT) |
commit | e6e43c867dae21a3312f75037880b20b2a41a252 (patch) | |
tree | 91b44e1d6715c782546d0e507861c93a9213f70d /Objects/stringlib | |
parent | cc7570fd900185f6b81c0c1b5b5a852b47c6ed80 (diff) | |
download | cpython-e6e43c867dae21a3312f75037880b20b2a41a252.zip cpython-e6e43c867dae21a3312f75037880b20b2a41a252.tar.gz cpython-e6e43c867dae21a3312f75037880b20b2a41a252.tar.bz2 |
needforspeed: stringlib refactoring: use stringlib/find for string find
Diffstat (limited to 'Objects/stringlib')
-rw-r--r-- | Objects/stringlib/find.h | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/Objects/stringlib/find.h b/Objects/stringlib/find.h index c2399ad..d5394b4 100644 --- a/Objects/stringlib/find.h +++ b/Objects/stringlib/find.h @@ -9,29 +9,38 @@ Py_LOCAL(Py_ssize_t) stringlib_find(const STRINGLIB_CHAR* str, Py_ssize_t str_len, - const STRINGLIB_CHAR* sub, Py_ssize_t sub_len) + const STRINGLIB_CHAR* sub, Py_ssize_t sub_len, + Py_ssize_t offset) { + Py_ssize_t pos; + if (sub_len == 0) - return 0; + return offset; + + pos = fastsearch(str, str_len, sub, sub_len, FAST_SEARCH); - return fastsearch(str, str_len, sub, sub_len, FAST_SEARCH); + if (pos >= 0) + pos += offset; + + return pos; } Py_LOCAL(Py_ssize_t) stringlib_rfind(const STRINGLIB_CHAR* str, Py_ssize_t str_len, - const STRINGLIB_CHAR* sub, Py_ssize_t sub_len) + const STRINGLIB_CHAR* sub, Py_ssize_t sub_len, + Py_ssize_t offset) { Py_ssize_t pos; /* XXX - create reversefastsearch helper! */ if (sub_len == 0) - pos = str_len; + pos = 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; + pos = j + offset; break; } } |