diff options
author | Raymond Hettinger <python@rcn.com> | 2015-06-28 05:03:35 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2015-06-28 05:03:35 (GMT) |
commit | 2eff9e9441d76904792141b4b38b0eb649d9eb86 (patch) | |
tree | 6bc66764729b5b5016483a3b77dd0f41806167f6 /Objects/setobject.c | |
parent | b5048d3938f8223ea88daeacf64130cde05f9a77 (diff) | |
download | cpython-2eff9e9441d76904792141b4b38b0eb649d9eb86.zip cpython-2eff9e9441d76904792141b4b38b0eb649d9eb86.tar.gz cpython-2eff9e9441d76904792141b4b38b0eb649d9eb86.tar.bz2 |
Minor refactoring. Move reference count logic into function that adds entry.
Diffstat (limited to 'Objects/setobject.c')
-rw-r--r-- | Objects/setobject.c | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c index 85cb4bc..09d1129 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -125,11 +125,6 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash) } } -/* -Internal routine to insert a new key into the table. -Used by the public insert routine. -Eats a reference to key. -*/ static int set_insert_key(PySetObject *so, PyObject *key, Py_hash_t hash) { @@ -213,6 +208,7 @@ set_insert_key(PySetObject *so, PyObject *key, Py_hash_t hash) } found_null_first: + Py_INCREF(key); so->fill++; so->used++; entry->key = key; @@ -220,6 +216,7 @@ set_insert_key(PySetObject *so, PyObject *key, Py_hash_t hash) return 0; found_null: + Py_INCREF(key); if (freeslot == NULL) { /* UNUSED */ so->fill++; @@ -233,7 +230,6 @@ set_insert_key(PySetObject *so, PyObject *key, Py_hash_t hash) return 0; found_active: - Py_DECREF(key); return 0; } @@ -381,11 +377,8 @@ set_add_entry(PySetObject *so, setentry *entry) assert(so->fill <= so->mask); /* at least one empty slot */ n_used = so->used; - Py_INCREF(key); - if (set_insert_key(so, key, hash)) { - Py_DECREF(key); + if (set_insert_key(so, key, hash)) return -1; - } if (!(so->used > n_used && so->fill*3 >= (so->mask+1)*2)) return 0; return set_table_resize(so, so->used>50000 ? so->used*2 : so->used*4); @@ -678,11 +671,8 @@ set_merge(PySetObject *so, PyObject *otherset) for (i = 0; i <= other->mask; i++, other_entry++) { key = other_entry->key; if (key != NULL && key != dummy) { - Py_INCREF(key); - if (set_insert_key(so, key, other_entry->hash)) { - Py_DECREF(key); + if (set_insert_key(so, key, other_entry->hash)) return -1; - } } } return 0; |