summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2013-08-22 15:20:31 (GMT)
committerRaymond Hettinger <python@rcn.com>2013-08-22 15:20:31 (GMT)
commitfcf3b500baceda678e0fd345a8bf1d694501c740 (patch)
tree94a959178bb4c4bcb2eb1edc8e8f3a5fa18a0718 /Objects
parente39e54d0b3433cc9f9e1d989c0edde1806b61396 (diff)
downloadcpython-fcf3b500baceda678e0fd345a8bf1d694501c740.zip
cpython-fcf3b500baceda678e0fd345a8bf1d694501c740.tar.gz
cpython-fcf3b500baceda678e0fd345a8bf1d694501c740.tar.bz2
Issue 18797: Remove unneeded refcount adjustments for dummy objects.
It suffices to keep just one reference when the object is created.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/setobject.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index f84c929..94789c6 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -274,7 +274,6 @@ set_insert_key(PySetObject *so, PyObject *key, Py_hash_t hash)
entry->key = key;
entry->hash = hash;
so->used++;
- Py_DECREF(dummy);
} else {
/* ACTIVE */
Py_DECREF(key);
@@ -381,23 +380,15 @@ set_table_resize(PySetObject *so, Py_ssize_t minused)
so->table = newtable;
so->mask = newsize - 1;
memset(newtable, 0, sizeof(setentry) * newsize);
+ i = so->used;
so->used = 0;
- i = so->fill;
so->fill = 0;
/* Copy the data over; this is refcount-neutral for active entries;
dummy entries aren't copied over, of course */
dummy_entry = dummy;
for (entry = oldtable; i > 0; entry++) {
- if (entry->key == NULL) {
- /* UNUSED */
- ;
- } else if (entry->key == dummy_entry) {
- /* DUMMY */
- --i;
- assert(entry->key == dummy);
- Py_DECREF(entry->key);
- } else {
+ if (entry->key != NULL && entry->key != dummy_entry) {
/* ACTIVE */
--i;
set_insert_clean(so, entry->key, entry->hash);
@@ -468,7 +459,6 @@ set_discard_entry(PySetObject *so, setentry *oldentry)
if (entry->key == NULL || entry->key == dummy)
return DISCARD_NOTFOUND;
old_key = entry->key;
- Py_INCREF(dummy);
entry->key = dummy;
so->used--;
Py_DECREF(old_key);
@@ -496,7 +486,6 @@ set_discard_key(PySetObject *so, PyObject *key)
if (entry->key == NULL || entry->key == dummy)
return DISCARD_NOTFOUND;
old_key = entry->key;
- Py_INCREF(dummy);
entry->key = dummy;
so->used--;
Py_DECREF(old_key);
@@ -554,7 +543,8 @@ set_clear_internal(PySetObject *so)
#endif
if (entry->key) {
--fill;
- Py_DECREF(entry->key);
+ if (entry->key != dummy)
+ Py_DECREF(entry->key);
}
#ifdef Py_DEBUG
else
@@ -615,7 +605,8 @@ set_dealloc(PySetObject *so)
for (entry = so->table; fill > 0; entry++) {
if (entry->key) {
--fill;
- Py_DECREF(entry->key);
+ if (entry->key != dummy)
+ Py_DECREF(entry->key);
}
}
if (so->table != so->smalltable)
@@ -788,7 +779,6 @@ set_pop(PySetObject *so)
}
}
key = entry->key;
- Py_INCREF(dummy);
entry->key = dummy;
so->used--;
so->table[0].hash = i + 1; /* next place to start */