Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
507d9977
Commit
507d9977
authored
May 18, 2014
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add comment and make minor code clean-up to improve clarity.
parent
4c5a187c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
3 deletions
+13
-3
Modules/_collectionsmodule.c
Modules/_collectionsmodule.c
+13
-3
No files found.
Modules/_collectionsmodule.c
View file @
507d9977
...
...
@@ -1831,6 +1831,16 @@ _count_elements(PyObject *self, PyObject *args)
if
(
mapping_get
!=
NULL
&&
mapping_get
==
dict_get
&&
mapping_setitem
!=
NULL
&&
mapping_setitem
==
dict_setitem
)
{
while
(
1
)
{
/* Fast path advantages:
1. Eliminate double hashing
(by re-using the same hash for both the get and set)
2. Avoid argument overhead of PyObject_CallFunctionObjArgs
(argument tuple creation and parsing)
3. Avoid indirection through a bound method object
(creates another argument tuple)
4. Avoid initial increment from zero
(reuse an existing one-object instead)
*/
Py_hash_t
hash
;
key
=
PyIter_Next
(
it
);
...
...
@@ -1848,13 +1858,13 @@ _count_elements(PyObject *self, PyObject *args)
oldval
=
_PyDict_GetItem_KnownHash
(
mapping
,
key
,
hash
);
if
(
oldval
==
NULL
)
{
if
(
_PyDict_SetItem_KnownHash
(
mapping
,
key
,
one
,
hash
)
==
-
1
)
break
;
goto
done
;
}
else
{
newval
=
PyNumber_Add
(
oldval
,
one
);
if
(
newval
==
NULL
)
break
;
goto
done
;
if
(
_PyDict_SetItem_KnownHash
(
mapping
,
key
,
newval
,
hash
)
==
-
1
)
break
;
goto
done
;
Py_CLEAR
(
newval
);
}
Py_DECREF
(
key
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment