Skip to content

Commit

Permalink
Fast case for count from zero
Browse files Browse the repository at this point in the history
  • Loading branch information
rhettinger committed Jun 25, 2024
1 parent ace2045 commit 34bf546
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 34bf546

Please sign in to comment.