4 ms·
That link shows that yes, "_count_elements" is implemented in Python, but right after it pulls in the C version if available (which it presumably is in CPython)
by benhoyt 6y ago
That link shows that yes, "_count_elements" is implemented in Python, but right after it pulls in the C version if available (which it presumably is in CPython):
try: # Load C helper function if available
from _collections import _count_elements
except ImportError:
pass
Here is the C version (with a comment a little way down describing the "fast path advantages": https://github.com/python/cpython/blob/93d33b47af70ede473f82d7953509a0607259c31/Modules/_collectionsmodule.c#L2277 https://github.com/python/cpython/blob/93d33b47af70ede473f82...
- MaxBarraclough 6y agoWell spotted, thanks.