diff options
author | Raymond Hettinger <python@rcn.com> | 2015-07-31 14:58:56 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2015-07-31 14:58:56 (GMT) |
commit | daffc916aabb8424b6708039e64054f792fb660d (patch) | |
tree | faeeb6ab1dad3dd6a7589dddbb24b6503ee6f21c /Objects/setobject.c | |
parent | 746f6af7159ef2a8d0662b5dc88697e1574cf0b3 (diff) | |
download | cpython-daffc916aabb8424b6708039e64054f792fb660d.zip cpython-daffc916aabb8424b6708039e64054f792fb660d.tar.gz cpython-daffc916aabb8424b6708039e64054f792fb660d.tar.bz2 |
Issue #24681: Move the most likely test first in set_add_entry().
Diffstat (limited to 'Objects/setobject.c')
-rw-r--r-- | Objects/setobject.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c index 0e443c4..c590bbf 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -171,12 +171,15 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash) 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 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash) 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) |