diff options
Diffstat (limited to 'Objects/rangeobject.c')
-rw-r--r-- | Objects/rangeobject.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index c4ba715018..0e9eb20154 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -5,7 +5,7 @@ /* Support objects whose length is > PY_SSIZE_T_MAX. - This could be sped up for small PyLongs if they fit in an Py_ssize_t. + This could be sped up for small PyLongs if they fit in a Py_ssize_t. This only matters on Win64. Though we could use PY_LONG_LONG which would presumably help perf. */ @@ -994,15 +994,14 @@ static PyObject * longrangeiter_setstate(longrangeiterobject *r, PyObject *state) { int cmp; - + /* clip the value */ PyObject *zero = PyLong_FromLong(0); if (zero == NULL) return NULL; cmp = PyObject_RichCompareBool(state, zero, Py_LT); if (cmp > 0) { - Py_CLEAR(r->index); - r->index = zero; + Py_XSETREF(r->index, zero); Py_RETURN_NONE; } Py_DECREF(zero); @@ -1014,10 +1013,9 @@ longrangeiter_setstate(longrangeiterobject *r, PyObject *state) return NULL; if (cmp > 0) state = r->len; - - Py_CLEAR(r->index); - r->index = state; - Py_INCREF(r->index); + + Py_INCREF(state); + Py_XSETREF(r->index, state); Py_RETURN_NONE; } @@ -1066,8 +1064,7 @@ longrangeiter_next(longrangeiterobject *r) result = PyNumber_Add(r->start, product); Py_DECREF(product); if (result) { - Py_DECREF(r->index); - r->index = new_index; + Py_SETREF(r->index, new_index); } else { Py_DECREF(new_index); |