summaryrefslogtreecommitdiffstats
path: root/Objects/enumobject.c
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2022-01-18 08:02:35 (GMT)
committerGitHub <noreply@github.com>2022-01-18 08:02:35 (GMT)
commit243c31667cc15a9a338330ad9b2a29b1cd1c76ec (patch)
treedf4b4382a31cd4a29d03109bdeeb400a199e0cf2 /Objects/enumobject.c
parenta287b31bcb065e4122400cb59167340d25480e6d (diff)
downloadcpython-243c31667cc15a9a338330ad9b2a29b1cd1c76ec.zip
cpython-243c31667cc15a9a338330ad9b2a29b1cd1c76ec.tar.gz
cpython-243c31667cc15a9a338330ad9b2a29b1cd1c76ec.tar.bz2
bpo-42161: Hoist the _PyLong_GetOne() call out of the inner loop. (GH-30656)
Diffstat (limited to 'Objects/enumobject.c')
-rw-r--r--Objects/enumobject.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index b78230d..8fbf4fd 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -16,9 +16,10 @@ class reversed "reversedobject *" "&PyReversed_Type"
typedef struct {
PyObject_HEAD
Py_ssize_t en_index; /* current index of enumeration */
- PyObject* en_sit; /* secondary iterator of enumeration */
+ PyObject* en_sit; /* secondary iterator of enumeration */
PyObject* en_result; /* result tuple */
PyObject* en_longindex; /* index for sequences >= PY_SSIZE_T_MAX */
+ PyObject* one; /* borrowed reference */
} enumobject;
@@ -78,6 +79,7 @@ enum_new_impl(PyTypeObject *type, PyObject *iterable, PyObject *start)
Py_DECREF(en);
return NULL;
}
+ en->one = _PyLong_GetOne(); /* borrowed reference */
return (PyObject *)en;
}
@@ -157,7 +159,7 @@ enum_next_long(enumobject *en, PyObject* next_item)
}
next_index = en->en_longindex;
assert(next_index != NULL);
- stepped_up = PyNumber_Add(next_index, _PyLong_GetOne());
+ stepped_up = PyNumber_Add(next_index, en->one);
if (stepped_up == NULL) {
Py_DECREF(next_item);
return NULL;