diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-12-27 13:51:32 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-12-27 13:51:32 (GMT) |
commit | 1ed017ae92b32b27186d5793f6e58c526f350a2b (patch) | |
tree | 05fec1ee9e107911f46d85f86efcabce50ff5680 /Modules/itertoolsmodule.c | |
parent | 726fc139a5f40d81a0013c856be1283da08de4a0 (diff) | |
download | cpython-1ed017ae92b32b27186d5793f6e58c526f350a2b.zip cpython-1ed017ae92b32b27186d5793f6e58c526f350a2b.tar.gz cpython-1ed017ae92b32b27186d5793f6e58c526f350a2b.tar.bz2 |
Issue #20440: Cleaning up the code by using Py_SETREF and Py_CLEAR.
Old code is correct, but with Py_SETREF and Py_CLEAR it can be cleaner.
This patch doesn't fix bugs and hence there is no need to backport it.
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r-- | Modules/itertoolsmodule.c | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 2bd0594..a4ffa06 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -77,7 +77,7 @@ groupby_traverse(groupbyobject *gbo, visitproc visit, void *arg) static PyObject * groupby_next(groupbyobject *gbo) { - PyObject *newvalue, *newkey, *r, *grouper, *tmp; + PyObject *newvalue, *newkey, *r, *grouper; /* skip to next iteration group */ for (;;) { @@ -110,19 +110,12 @@ groupby_next(groupbyobject *gbo) } } - tmp = gbo->currkey; - gbo->currkey = newkey; - Py_XDECREF(tmp); - - tmp = gbo->currvalue; - gbo->currvalue = newvalue; - Py_XDECREF(tmp); + Py_SETREF(gbo->currkey, newkey); + Py_SETREF(gbo->currvalue, newvalue); } Py_INCREF(gbo->currkey); - tmp = gbo->tgtkey; - gbo->tgtkey = gbo->currkey; - Py_XDECREF(tmp); + Py_SETREF(gbo->tgtkey, gbo->currkey); grouper = _grouper_create(gbo, gbo->tgtkey); if (grouper == NULL) @@ -3445,7 +3438,7 @@ accumulate_traverse(accumulateobject *lz, visitproc visit, void *arg) static PyObject * accumulate_next(accumulateobject *lz) { - PyObject *val, *oldtotal, *newtotal; + PyObject *val, *newtotal; val = (*Py_TYPE(lz->it)->tp_iternext)(lz->it); if (val == NULL) @@ -3465,11 +3458,8 @@ accumulate_next(accumulateobject *lz) if (newtotal == NULL) return NULL; - oldtotal = lz->total; - lz->total = newtotal; - Py_DECREF(oldtotal); - Py_INCREF(newtotal); + Py_SETREF(lz->total, newtotal); return newtotal; } |