summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2012-10-23 00:52:18 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2012-10-23 00:52:18 (GMT)
commitfe75fb4b3e8687a68ea6bb7c4e894434a177c66a (patch)
tree9e702eb3f69db6f73aa0a99bc2303392e9aee1ec /Objects
parent6fa627578a52bda0efee1619ddbadf6be0aa6591 (diff)
downloadcpython-fe75fb4b3e8687a68ea6bb7c4e894434a177c66a.zip
cpython-fe75fb4b3e8687a68ea6bb7c4e894434a177c66a.tar.gz
cpython-fe75fb4b3e8687a68ea6bb7c4e894434a177c66a.tar.bz2
Optimize _PyUnicode_HasNULChars(): use findchar() instead of PyUnicode_Contains()
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 362f2cf..a7efb01 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -3573,18 +3573,20 @@ PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
int
-_PyUnicode_HasNULChars(PyObject* s)
+_PyUnicode_HasNULChars(PyObject* str)
{
- static PyObject *nul = NULL;
+ Py_ssize_t pos;
- if (nul == NULL)
- nul = PyUnicode_FromStringAndSize("\0", 1);
- if (nul == NULL)
+ if (PyUnicode_READY(str) == -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
PyUnicode_FSConverter(PyObject* arg, void* addr)
{