summaryrefslogtreecommitdiffstats
path: root/Objects/stringobject.c
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2006-05-26 19:48:07 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2006-05-26 19:48:07 (GMT)
commite6e43c867dae21a3312f75037880b20b2a41a252 (patch)
tree91b44e1d6715c782546d0e507861c93a9213f70d /Objects/stringobject.c
parentcc7570fd900185f6b81c0c1b5b5a852b47c6ed80 (diff)
downloadcpython-e6e43c867dae21a3312f75037880b20b2a41a252.zip
cpython-e6e43c867dae21a3312f75037880b20b2a41a252.tar.gz
cpython-e6e43c867dae21a3312f75037880b20b2a41a252.tar.bz2
needforspeed: stringlib refactoring: use stringlib/find for string find
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r--Objects/stringobject.c25
1 files changed, 6 insertions, 19 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 75325ab..8d2a0be 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -775,6 +775,8 @@ PyString_AsStringAndSize(register PyObject *obj,
#define STRINGLIB_EMPTY nullstring
#include "stringlib/fastsearch.h"
+
+#include "stringlib/find.h"
#include "stringlib/partition.h"
/* -------------------------------------------------------------------- */
@@ -1876,25 +1878,10 @@ string_find_internal(PyStringObject *self, PyObject *args, int dir)
string_adjust_indices(&i, &last, len);
- if (n == 0)
- return (dir > 0) ? i : last;
- if (dir > 0) {
- Py_ssize_t pos = fastsearch(s + i, last - i, sub, n,
- FAST_SEARCH);
- if (pos < 0)
- return pos;
- return pos + i;
- } else {
- Py_ssize_t j;
-
- if (n == 0 && i <= last)
- return last;
- for (j = last-n; j >= i; --j)
- if (s[j] == sub[0] && memcmp(&s[j], sub, n) == 0)
- return j;
- }
-
- return -1;
+ if (dir > 0)
+ return stringlib_find(s+i, last-i, sub, n, i);
+ else
+ return stringlib_rfind(s+i, last-i, sub, n, i);
}