Skip to content

Commit edf016b

Browse files
committed
review comments
1 parent ff7709c commit edf016b

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

Modules/itertoolsmodule.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3531,25 +3531,26 @@ count_traverse(PyObject *op, visitproc visit, void *arg)
35313531
static PyObject *
35323532
count_nextlong(countobject *lz)
35333533
{
3534-
PyObject *long_cnt;
3535-
PyObject *stepped_up;
3536-
3537-
long_cnt = lz->long_cnt;
3538-
if (long_cnt == NULL) {
3534+
if (lz->long_cnt == NULL) {
35393535
/* Switch to slow_mode */
3540-
long_cnt = PyLong_FromSsize_t(PY_SSIZE_T_MAX);
3541-
if (long_cnt == NULL) {
3536+
lz->long_cnt = PyLong_FromSsize_t(PY_SSIZE_T_MAX);
3537+
if (lz->long_cnt == NULL) {
35423538
return NULL;
35433539
}
3544-
lz->long_cnt = long_cnt;
35453540
}
3546-
assert(lz->cnt == PY_SSIZE_T_MAX && long_cnt != NULL);
3541+
assert(lz->cnt == PY_SSIZE_T_MAX && lz->long_cnt != NULL);
3542+
3543+
// We hold one reference to "result" (a.k.a. the old value of
3544+
// lz->long_cnt); we'll either return it or keep it in lz->long_cnt.
3545+
PyObject *result = lz->long_cnt;
35473546

3548-
stepped_up = PyNumber_Add(long_cnt, lz->long_step);
3549-
if (stepped_up == NULL)
3547+
PyObject *stepped_up = PyNumber_Add(result, lz->long_step);
3548+
if (stepped_up == NULL) {
35503549
return NULL;
3550+
}
35513551
lz->long_cnt = stepped_up;
3552-
return long_cnt;
3552+
3553+
return result;
35533554
}
35543555

35553556
static PyObject *

0 commit comments

Comments
 (0)