[Python-checkins] cpython: Add comment and make minor code clean-up to improve clarity.
raymond.hettinger
python-checkins at python.org
Sun May 18 22:32:59 CEST 2014
http://hg.python.org/cpython/rev/e4d6983c528f
changeset: 90756:e4d6983c528f
parent: 90749:de01f7c37b53
user: Raymond Hettinger <python at rcn.com>
date: Sun May 18 21:32:40 2014 +0100
summary:
Add comment and make minor code clean-up to improve clarity.
files:
Modules/_collectionsmodule.c | 16 +++++++++++++---
1 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -1831,6 +1831,16 @@
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 @@
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);
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list