[Python-checkins] cpython: if the kind of the string to count is larger than the string to search,

benjamin.peterson python-checkins at python.org
Fri May 4 00:31:12 CEST 2012


http://hg.python.org/cpython/rev/0ea729cc2a0b
changeset:   76737:0ea729cc2a0b
user:        Benjamin Peterson <benjamin at python.org>
date:        Thu May 03 18:31:07 2012 -0400
summary:
  if the kind of the string to count is larger than the string to search, shortcut to 0

files:
  Objects/unicodeobject.c |  13 +++----------
  1 files changed, 3 insertions(+), 10 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -11187,20 +11187,15 @@
 
     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 @@
 
     result = PyLong_FromSsize_t(iresult);
 
-    if (kind1 != kind)
-        PyMem_Free(buf1);
     if (kind2 != kind)
         PyMem_Free(buf2);
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list