Commit 7e3d09b2 authored by Fredrik Lundh's avatar Fredrik Lundh

needforspeed: stringlib refactoring: use stringlib/find for unicode

find
parent b00f1dbd
...@@ -3951,27 +3951,49 @@ static Py_ssize_t findstring(PyUnicodeObject *self, ...@@ -3951,27 +3951,49 @@ static Py_ssize_t findstring(PyUnicodeObject *self,
} }
Py_ssize_t PyUnicode_Find(PyObject *str, Py_ssize_t PyUnicode_Find(PyObject *str,
PyObject *substr, PyObject *substr,
Py_ssize_t start, Py_ssize_t start,
Py_ssize_t end, Py_ssize_t end,
int direction) int direction)
{ {
Py_ssize_t result; Py_ssize_t result;
PyUnicodeObject* str_obj;
PyUnicodeObject* sub_obj;
str = PyUnicode_FromObject(str); str_obj = (PyUnicodeObject*) PyUnicode_FromObject(str);
if (str == NULL) if (!str)
return -2; return -2;
substr = PyUnicode_FromObject(substr); sub_obj = (PyUnicodeObject*) PyUnicode_FromObject(substr);
if (substr == NULL) { if (!sub_obj) {
Py_DECREF(str); Py_DECREF(str_obj);
return -2; return -2;
} }
result = findstring((PyUnicodeObject *)str, if (start < 0)
(PyUnicodeObject *)substr, start += str_obj->length;
start, end, direction); if (start < 0)
Py_DECREF(str); start = 0;
Py_DECREF(substr); if (end > str_obj->length)
end = str_obj->length;
if (end < 0)
end += str_obj->length;
if (end < 0)
end = 0;
if (direction > 0)
result = stringlib_find(
str_obj->str + start, end - start, sub_obj->str, sub_obj->length
);
else
result = stringlib_rfind(
str_obj->str + start, end - start, sub_obj->str, sub_obj->length
);
if (result >= 0)
result += start;
Py_DECREF(str_obj);
Py_DECREF(sub_obj);
return result; return result;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment