diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-03-30 06:09:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-30 06:09:41 (GMT) |
commit | ba85d69a3e3610bdd05f0dd372cf4ebca178c7fb (patch) | |
tree | fe0766c34601880610c3399a8f01c35ab6e8fe8e /Modules/_collectionsmodule.c | |
parent | e6911a44f69c0d302db60f49952a9cf69da69a2b (diff) | |
download | cpython-ba85d69a3e3610bdd05f0dd372cf4ebca178c7fb.zip cpython-ba85d69a3e3610bdd05f0dd372cf4ebca178c7fb.tar.gz cpython-ba85d69a3e3610bdd05f0dd372cf4ebca178c7fb.tar.bz2 |
bpo-29878: Add global instances of int for 0 and 1. (#852)
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r-- | Modules/_collectionsmodule.c | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 44e9e11..b052535 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -2267,8 +2267,6 @@ _count_elements(PyObject *self, PyObject *args) PyObject *it, *iterable, *mapping, *oldval; PyObject *newval = NULL; PyObject *key = NULL; - PyObject *zero = NULL; - PyObject *one = NULL; PyObject *bound_get = NULL; PyObject *mapping_get; PyObject *dict_get; @@ -2282,10 +2280,6 @@ _count_elements(PyObject *self, PyObject *args) if (it == NULL) return NULL; - one = PyLong_FromLong(1); - if (one == NULL) - goto done; - /* Only take the fast path when get() and __setitem__() * have not been overridden. */ @@ -2325,10 +2319,10 @@ _count_elements(PyObject *self, PyObject *args) if (oldval == NULL) { if (PyErr_Occurred()) goto done; - if (_PyDict_SetItem_KnownHash(mapping, key, one, hash) < 0) + if (_PyDict_SetItem_KnownHash(mapping, key, _PyLong_One, hash) < 0) goto done; } else { - newval = PyNumber_Add(oldval, one); + newval = PyNumber_Add(oldval, _PyLong_One); if (newval == NULL) goto done; if (_PyDict_SetItem_KnownHash(mapping, key, newval, hash) < 0) @@ -2342,18 +2336,14 @@ _count_elements(PyObject *self, PyObject *args) if (bound_get == NULL) goto done; - zero = PyLong_FromLong(0); - if (zero == NULL) - goto done; - while (1) { key = PyIter_Next(it); if (key == NULL) break; - oldval = PyObject_CallFunctionObjArgs(bound_get, key, zero, NULL); + oldval = PyObject_CallFunctionObjArgs(bound_get, key, _PyLong_Zero, NULL); if (oldval == NULL) break; - newval = PyNumber_Add(oldval, one); + newval = PyNumber_Add(oldval, _PyLong_One); Py_DECREF(oldval); if (newval == NULL) break; @@ -2369,8 +2359,6 @@ done: Py_XDECREF(key); Py_XDECREF(newval); Py_XDECREF(bound_get); - Py_XDECREF(zero); - Py_XDECREF(one); if (PyErr_Occurred()) return NULL; Py_RETURN_NONE; |