]> granicus.if.org Git - python/commitdiff
Make the unicode equality test an external function rather than in-lining it.
authorRaymond Hettinger <python@rcn.com>
Sat, 4 Jul 2015 23:04:44 +0000 (16:04 -0700)
committerRaymond Hettinger <python@rcn.com>
Sat, 4 Jul 2015 23:04:44 +0000 (16:04 -0700)
The real benefit of the unicode specialized function comes from
bypassing the overhead of PyObject_RichCompareBool() and not
from being in-lined (especially since there was almost no shared
data between the caller and callee).  Also, the in-lining was
having a negative effect on code generation for the callee.

Include/unicodeobject.h
Objects/setobject.c
Objects/unicodeobject.c

index 4ba632803c021343c57f920bbc246640f212e16f..33e8f19af088b4576ebf3c445b9105bbb7f73d5f 100644 (file)
@@ -2261,6 +2261,10 @@ PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*);
 /* Clear all static strings. */
 PyAPI_FUNC(void) _PyUnicode_ClearStaticStrings(void);
 
+/* Fast equality check when the inputs are known to be exact unicode types
+   and where the hash values are equal (i.e. a very probable match) */
+PyAPI_FUNC(int) _PyUnicode_EQ(PyObject *, PyObject *);
+
 #ifdef __cplusplus
 }
 #endif
index cc87f284f60d9111fcf1bb986fc2b6ad6b9a804f..d0fb4f14f443b9fc3fb1ed72918ba6c9bbc6a1ed 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "Python.h"
 #include "structmember.h"
-#include "stringlib/eq.h"
 
 /* Object used as dummy key to fill deleted entries */
 static PyObject _dummy_struct;
@@ -74,7 +73,7 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
                 return entry;
             if (PyUnicode_CheckExact(startkey)
                 && PyUnicode_CheckExact(key)
-                && unicode_eq(startkey, key))
+                && _PyUnicode_EQ(startkey, key))
                 return entry;
             Py_INCREF(startkey);
             cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
@@ -100,7 +99,7 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
                         return entry;
                     if (PyUnicode_CheckExact(startkey)
                         && PyUnicode_CheckExact(key)
-                        && unicode_eq(startkey, key))
+                        && _PyUnicode_EQ(startkey, key))
                         return entry;
                     Py_INCREF(startkey);
                     cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
@@ -155,7 +154,7 @@ set_insert_key(PySetObject *so, PyObject *key, Py_hash_t hash)
                 goto found_active;
             if (PyUnicode_CheckExact(startkey)
                 && PyUnicode_CheckExact(key)
-                && unicode_eq(startkey, key))
+                && _PyUnicode_EQ(startkey, key))
                 goto found_active;
             Py_INCREF(startkey);
             cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
@@ -183,7 +182,7 @@ set_insert_key(PySetObject *so, PyObject *key, Py_hash_t hash)
                         goto found_active;
                     if (PyUnicode_CheckExact(startkey)
                         && PyUnicode_CheckExact(key)
-                        && unicode_eq(startkey, key))
+                        && _PyUnicode_EQ(startkey, key))
                         goto found_active;
                     Py_INCREF(startkey);
                     cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
index 1eaf2e977d9cf72a571e691c7894d20289c7a6a8..796e0b4f27621a49d65aaf5dff3288dd7a8f63e6 100644 (file)
@@ -42,6 +42,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "Python.h"
 #include "ucnhash.h"
 #include "bytes_methods.h"
+#include "stringlib/eq.h"
 
 #ifdef MS_WINDOWS
 #include <windows.h>
@@ -10886,6 +10887,12 @@ PyUnicode_RichCompare(PyObject *left, PyObject *right, int op)
     return v;
 }
 
+int
+_PyUnicode_EQ(PyObject *aa, PyObject *bb)
+{
+    return unicode_eq(aa, bb);
+}
+
 int
 PyUnicode_Contains(PyObject *container, PyObject *element)
 {