From fe75fb4b3e8687a68ea6bb7c4e894434a177c66a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 23 Oct 2012 02:52:18 +0200 Subject: [PATCH] Optimize _PyUnicode_HasNULChars(): use findchar() instead of PyUnicode_Contains() --- Objects/unicodeobject.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 362f2cffcf1..a7efb01a042 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) {