diff options
Diffstat (limited to 'Objects/rangeobject.c')
| -rw-r--r-- | Objects/rangeobject.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index eaa48d5f44..babf55b108 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -582,13 +582,19 @@ range_index(rangeobject *r, PyObject *ob) return NULL; if (contains) { - PyObject *idx, *tmp = PyNumber_Subtract(ob, r->start); - if (tmp == NULL) + PyObject *idx = PyNumber_Subtract(ob, r->start); + if (idx == NULL) { return NULL; + } + + if (r->step == _PyLong_One) { + return idx; + } + /* idx = (ob - r.start) // r.step */ - idx = PyNumber_FloorDivide(tmp, r->step); - Py_DECREF(tmp); - return idx; + PyObject *sidx = PyNumber_FloorDivide(idx, r->step); + Py_DECREF(idx); + return sidx; } /* object is not in the range */ |
