[Python-checkins] cpython: Issue #24681: Move the most likely test first in set_add_entry().

raymond.hettinger python-checkins at python.org
Fri Jul 31 16:59:06 CEST 2015


https://hg.python.org/cpython/rev/9e3be159d023
changeset:   97163:9e3be159d023
user:        Raymond Hettinger <python at rcn.com>
date:        Fri Jul 31 07:58:56 2015 -0700
summary:
  Issue #24681:  Move the most likely test first in set_add_entry().

files:
  Objects/setobject.c |  15 +++++++++------
  1 files changed, 9 insertions(+), 6 deletions(-)


diff --git a/Objects/setobject.c b/Objects/setobject.c
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -171,12 +171,15 @@
             Py_INCREF(startkey);
             cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
             Py_DECREF(startkey);
-            if (cmp < 0)                                          /* unlikely */
-                goto comparison_error;
-            if (table != so->table || entry->key != startkey)     /* unlikely */
-                goto restart;
             if (cmp > 0)                                          /* likely */
                 goto found_active;
+            if (cmp < 0)
+                goto comparison_error;
+            /* Continuing the search from the current entry only makes
+               sense if the table and entry are unchanged; otherwise,
+               we have to restart from the beginning */
+            if (table != so->table || entry->key != startkey)
+                goto restart;
             mask = so->mask;                 /* help avoid a register spill */
         }
         else if (entry->hash == -1 && freeslot == NULL)
@@ -200,12 +203,12 @@
                     Py_INCREF(startkey);
                     cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
                     Py_DECREF(startkey);
+                    if (cmp > 0)
+                        goto found_active;
                     if (cmp < 0)
                         goto comparison_error;
                     if (table != so->table || entry->key != startkey)
                         goto restart;
-                    if (cmp > 0)
-                        goto found_active;
                     mask = so->mask;
                 }
                 else if (entry->hash == -1 && freeslot == NULL)

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


More information about the Python-checkins mailing list