]> granicus.if.org Git - python/commitdiff
Enable also ptr==ptr optimization in PyUnicode_Compare()
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 4 Oct 2012 19:53:50 +0000 (21:53 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 4 Oct 2012 19:53:50 +0000 (21:53 +0200)
It was already implemented in PyUnicode_RichCompare()

Include/unicodeobject.h
Objects/unicodeobject.c

index 135e4694b0f8ea2393326f336da08ecb13e13a15..956bdbda38bdda87331d08125a20d9f77747132d 100644 (file)
@@ -1951,7 +1951,8 @@ PyAPI_FUNC(PyObject *) PyUnicode_Replace(
     );
 
 /* Compare two strings and return -1, 0, 1 for less than, equal,
-   greater than resp. */
+   greater than resp.
+   Raise an exception and return -1 on error. */
 
 PyAPI_FUNC(int) PyUnicode_Compare(
     PyObject *left,             /* Left string */
index 98b10e95847f4be98fd0656debc9be75dc6613cb..b84d888fbcf1ebccbfdc9cd1faa47f3fd4c14e4d 100644 (file)
@@ -10445,6 +10445,10 @@ unicode_compare(PyObject *str1, PyObject *str2)
     void *data1, *data2;
     Py_ssize_t len1, len2, i;
 
+    /* a string is equal to itself */
+    if (str1 == str2)
+        return 0;
+
     kind1 = PyUnicode_KIND(str1);
     kind2 = PyUnicode_KIND(str2);
     data1 = PyUnicode_DATA(str1);
@@ -10531,10 +10535,7 @@ PyUnicode_RichCompare(PyObject *left, PyObject *right, int op)
                 return Py_True;
             }
         }
-        if (left == right)
-            result = 0;
-        else
-            result = unicode_compare(left, right);
+        result = unicode_compare(left, right);
 
         /* Convert the return value to a Boolean */
         switch (op) {