summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-05-03 22:31:07 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-05-03 22:31:07 (GMT)
commitb63f49f2b40807b1822f901c81561bd03ae04bd7 (patch)
treee5c7d6fb10f1292081f7876dd29b14f912efbf3a /Objects/unicodeobject.c
parenta7b654be305dc0be1cbe521eb8a3d05489de975c (diff)
downloadcpython-b63f49f2b40807b1822f901c81561bd03ae04bd7.zip
cpython-b63f49f2b40807b1822f901c81561bd03ae04bd7.tar.gz
cpython-b63f49f2b40807b1822f901c81561bd03ae04bd7.tar.bz2
if the kind of the string to count is larger than the string to search, shortcut to 0
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index d290da6..0816c3c 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -11187,20 +11187,15 @@ unicode_count(PyObject *self, PyObject *args)
kind1 = PyUnicode_KIND(self);
kind2 = PyUnicode_KIND(substring);
- kind = kind1 > kind2 ? kind1 : kind2;
+ if (kind2 > kind1)
+ return PyLong_FromLong(0);
+ kind = kind1;
buf1 = PyUnicode_DATA(self);
buf2 = PyUnicode_DATA(substring);
- if (kind1 != kind)
- buf1 = _PyUnicode_AsKind(self, kind);
- if (!buf1) {
- Py_DECREF(substring);
- return NULL;
- }
if (kind2 != kind)
buf2 = _PyUnicode_AsKind(substring, kind);
if (!buf2) {
Py_DECREF(substring);
- if (kind1 != kind) PyMem_Free(buf1);
return NULL;
}
len1 = PyUnicode_GET_LENGTH(self);
@@ -11232,8 +11227,6 @@ unicode_count(PyObject *self, PyObject *args)
result = PyLong_FromSsize_t(iresult);
- if (kind1 != kind)
- PyMem_Free(buf1);
if (kind2 != kind)
PyMem_Free(buf2);