mirror of https://github.com/python/cpython
bpo-41902: Micro optimization for compute_item of range (GH-22492)
This commit is contained in:
parent
a460d45063
commit
25492a5b59
|
@ -0,0 +1,3 @@
|
|||
Micro optimization when compute :c:member:`~PySequenceMethods.sq_item` and
|
||||
:c:member:`~PyMappingMethods.mp_subscript` of :class:`range`. Patch by
|
||||
Dong-hee Na.
|
|
@ -254,11 +254,17 @@ compute_item(rangeobject *r, PyObject *i)
|
|||
/* PyLong equivalent to:
|
||||
* return r->start + (i * r->step)
|
||||
*/
|
||||
if (r->step == _PyLong_One) {
|
||||
result = PyNumber_Add(r->start, i);
|
||||
}
|
||||
else {
|
||||
incr = PyNumber_Multiply(i, r->step);
|
||||
if (!incr)
|
||||
if (!incr) {
|
||||
return NULL;
|
||||
}
|
||||
result = PyNumber_Add(r->start, incr);
|
||||
Py_DECREF(incr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue