https://github.com/python/cpython/commit/9b32b890749b7843cd3e087baa89390fde634859
commit: 9b32b890749b7843cd3e087baa89390fde634859
branch: main
author: Raymond Hettinger <[email protected]>
committer: rhettinger <[email protected]>
date: 2024-06-25T03:10:00-05:00
summary:
Add fast path in count_elements (gh-120983)
files:
M Modules/_collectionsmodule.c
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 644a90a8c71099..641d57a64c8357 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -2575,7 +2575,11 @@ _collections__count_elements_impl(PyObject *module,
PyObject *mapping,
oldval = PyObject_CallFunctionObjArgs(bound_get, key, zero, NULL);
if (oldval == NULL)
break;
- newval = PyNumber_Add(oldval, one);
+ if (oldval == zero) {
+ newval = Py_NewRef(one);
+ } else {
+ newval = PyNumber_Add(oldval, one);
+ }
Py_DECREF(oldval);
if (newval == NULL)
break;
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]