summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2015-01-27 05:54:35 (GMT)
committerRaymond Hettinger <python@rcn.com>2015-01-27 05:54:35 (GMT)
commita5ebbf6295fef4e9033774f5c711a53407d766c9 (patch)
treee1739e041ca98f6d0b3e6e8ffcf7a577eb3a1580 /Objects
parent3037e84ad14424759298966579dbcce77a212621 (diff)
downloadcpython-a5ebbf6295fef4e9033774f5c711a53407d766c9.zip
cpython-a5ebbf6295fef4e9033774f5c711a53407d766c9.tar.gz
cpython-a5ebbf6295fef4e9033774f5c711a53407d766c9.tar.bz2
Remove unneeded dummy test from the set search loop (when the hashes match we know the key is not a dummy).
Diffstat (limited to 'Objects')
-rw-r--r--Objects/setobject.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index dc33a34..673490d 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -65,8 +65,10 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
return entry;
while (1) {
- if (entry->hash == hash && entry->key != dummy) { /* dummy match unlikely */
+ if (entry->hash == hash) {
PyObject *startkey = entry->key;
+ /* startkey cannot be a dummy because the dummy hash field is -1 */
+ assert(startkey != dummy);
if (startkey == key)
return entry;
if (PyUnicode_CheckExact(startkey)
@@ -83,15 +85,18 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
if (cmp > 0) /* likely */
return entry;
}
- if (entry->key == dummy && freeslot == NULL)
+ if (entry->hash == -1 && freeslot == NULL) {
+ assert(entry->key == dummy);
freeslot = entry;
+ }
for (j = 1 ; j <= LINEAR_PROBES ; j++) {
entry = &table[(i + j) & mask];
if (entry->key == NULL)
goto found_null;
- if (entry->hash == hash && entry->key != dummy) {
+ if (entry->hash == hash) {
PyObject *startkey = entry->key;
+ assert(startkey != dummy);
if (startkey == key)
return entry;
if (PyUnicode_CheckExact(startkey)
@@ -108,8 +113,10 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
if (cmp > 0)
return entry;
}
- if (entry->key == dummy && freeslot == NULL)
+ if (entry->hash == -1 && freeslot == NULL) {
+ assert(entry->key == dummy);
freeslot = entry;
+ }
}
perturb >>= PERTURB_SHIFT;