cpython: 828c9b920532 (original) (raw)

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Release date: XXXX-XX-XX Core and Builtins ----------------- +- Issue #25462: The hash of the key now is calculated only once in most

--- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -88,15 +88,16 @@ For adding nodes:

@@ -582,15 +583,11 @@ static int /* Return the index into the hash table, regardless of a valid node. */ static Py_ssize_t -_odict_get_index(PyODictObject *od, PyObject *key) +_odict_get_index(PyODictObject *od, PyObject *key, Py_hash_t hash) {

} /* Returns NULL if there was some error or the key was not found. */ static _ODictNode * -_odict_find_node(PyODictObject *od, PyObject *key) +_odict_find_node_hash(PyODictObject *od, PyObject *key, Py_hash_t hash) { Py_ssize_t index; if (_odict_EMPTY(od)) return NULL;

+} + +static _ODictNode * +_odict_find_node(PyODictObject *od, PyObject *key) +{

+

- Py_INCREF(key);

@@ -728,7 +737,8 @@ static void we modify od_fast_nodes. */ static int -_odict_clear_node(PyODictObject *od, _ODictNode *node, PyObject *key) +_odict_clear_node(PyODictObject *od, _ODictNode *node, PyObject *key,

{ Py_ssize_t i; @@ -738,7 +748,7 @@ static int return 0; }

@@ -1091,7 +1101,8 @@ odict_pop(PyObject *od, PyObject *args, } static PyObject * -_odict_popkey(PyObject *od, PyObject *key, PyObject *failobj) +_odict_popkey_hash(PyObject *od, PyObject *key, PyObject *failobj,

{ _ODictNode *node; PyObject *value = NULL; @@ -1099,13 +1110,13 @@ static PyObject / Pop the node first to avoid a possible dict resize (due to eval loop reentrancy) and complications due to hash collision resolution. */

@@ -1114,8 +1125,14 @@ static PyObject / Now delete the value from the dict. */ if (PyODict_CheckExact(od)) { if (node != NULL) {

+

+} + /* popitem() */ PyDoc_STRVAR(odict_popitem__doc__, @@ -1178,7 +1205,7 @@ odict_popitem(PyObject *od, PyObject *ar node = last ? _odict_LAST(od) : _odict_FIRST(od); key = _odictnode_KEY(node); Py_INCREF(key);

+ PyDoc_STRVAR(odict_copy__doc__, "od.copy() -> a shallow copy of od"); static PyObject * @@ -1261,7 +1292,8 @@ odict_copy(register PyODictObject *od) PyErr_SetObject(PyExc_KeyError, key); goto fail; }

+static int +_PyODict_SetItem_KnownHash(PyObject *od, PyObject *key, PyObject *value,

+{

+PyODict_SetItem(PyObject *od, PyObject *key, PyObject *value) +{

+}; + +int +PyODict_DelItem(PyObject *od, PyObject *key) +{

};