Optimize _PyUnicode_HasNULChars(): use findchar() instead of PyUnicode_Contains()

This commit is contained in:
Victor Stinner 2012-10-23 02:52:18 +02:00
parent 6fa627578a
commit fe75fb4b3e
1 changed files with 9 additions and 7 deletions

View File

@ -3573,18 +3573,20 @@ PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
int int
_PyUnicode_HasNULChars(PyObject* s) _PyUnicode_HasNULChars(PyObject* str)
{ {
static PyObject *nul = NULL; Py_ssize_t pos;
if (nul == NULL) if (PyUnicode_READY(str) == -1)
nul = PyUnicode_FromStringAndSize("\0", 1);
if (nul == NULL)
return -1; return -1;
return PyUnicode_Contains(s, nul); pos = findchar(PyUnicode_DATA(str), PyUnicode_KIND(str),
PyUnicode_GET_LENGTH(str), '\0', 1);
if (pos == -1)
return 0;
else
return 1;
} }
int int
PyUnicode_FSConverter(PyObject* arg, void* addr) PyUnicode_FSConverter(PyObject* arg, void* addr)
{ {