homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients corona10, rhettinger, vstinner
Date 2020年10月27日.20:15:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1603829719.08.0.0883741055634.issue42161@roundup.psfhosted.org>
In-reply-to
Content
Why did you put _PyLong_GetOne() inside the loop for the fast path and outside the loop for the slow path?
==========================================================================
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 8990071f51..0e6c64d1a6 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -2278,6 +2278,8 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping,
 PyObject *dict_get;
 PyObject *mapping_setitem;
 PyObject *dict_setitem;
+ PyObject *zero = _PyLong_GetZero(); // borrowed reference
+ PyObject *one = _PyLong_GetOne(); // borrowed reference
 it = PyObject_GetIter(iterable);
 if (it == NULL)
@@ -2324,10 +2326,10 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping,
 if (oldval == NULL) {
 if (PyErr_Occurred())
 goto done;
- if (_PyDict_SetItem_KnownHash(mapping, key, _PyLong_GetOne(), hash) < 0)
+ if (_PyDict_SetItem_KnownHash(mapping, key, one, hash) < 0)
 goto done;
 } else {
- newval = PyNumber_Add(oldval, _PyLong_GetOne());
+ newval = PyNumber_Add(oldval, one);
 if (newval == NULL)
 goto done;
 if (_PyDict_SetItem_KnownHash(mapping, key, newval, hash) < 0)
@@ -2341,8 +2343,6 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping,
 if (bound_get == NULL)
 goto done;
- PyObject *zero = _PyLong_GetZero(); // borrowed reference
- PyObject *one = _PyLong_GetOne(); // borrowed reference
 while (1) {
 key = PyIter_Next(it);
 if (key == NULL)
History
Date User Action Args
2020年10月27日 20:15:19rhettingersetrecipients: + rhettinger, vstinner, corona10
2020年10月27日 20:15:19rhettingersetmessageid: <1603829719.08.0.0883741055634.issue42161@roundup.psfhosted.org>
2020年10月27日 20:15:19rhettingerlinkissue42161 messages
2020年10月27日 20:15:18rhettingercreate

AltStyle によって変換されたページ (->オリジナル) /