summaryrefslogtreecommitdiffstats
path: root/Objects/odictobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-09-08 00:40:12 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-09-08 00:40:12 (GMT)
commit742da040db28e1284615e88874d5c952da80344e (patch)
treecab46d2fca910251fdfd92e248a2a484246f9354 /Objects/odictobject.c
parentd8b7770a0e4a79280a3b5346ae8a6593ea74facf (diff)
downloadcpython-742da040db28e1284615e88874d5c952da80344e.zip
cpython-742da040db28e1284615e88874d5c952da80344e.tar.gz
cpython-742da040db28e1284615e88874d5c952da80344e.tar.bz2
Implement compact dict
Issue #27350: `dict` implementation is changed like PyPy. It is more compact and preserves insertion order. _PyDict_Dummy() function has been removed. Disable test_gdb: python-gdb.py is not updated yet to the new structure of compact dictionaries (issue #28023). Patch written by INADA Naoki.
Diffstat (limited to 'Objects/odictobject.c')
-rw-r--r--Objects/odictobject.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/Objects/odictobject.c b/Objects/odictobject.c
index f056074..fe47098 100644
--- a/Objects/odictobject.c
+++ b/Objects/odictobject.c
@@ -536,14 +536,17 @@ static Py_ssize_t
_odict_get_index_raw(PyODictObject *od, PyObject *key, Py_hash_t hash)
{
PyObject **value_addr = NULL;
- PyDictKeyEntry *ep;
PyDictKeysObject *keys = ((PyDictObject *)od)->ma_keys;
+ Py_ssize_t ix;
- ep = (keys->dk_lookup)((PyDictObject *)od, key, hash, &value_addr);
- if (ep == NULL)
+ ix = (keys->dk_lookup)((PyDictObject *)od, key, hash, &value_addr, NULL);
+ if (ix == DKIX_EMPTY) {
+ return keys->dk_nentries; /* index of new entry */
+ }
+ if (ix < 0)
return -1;
/* We use pointer arithmetic to get the entry's index into the table. */
- return ep - keys->dk_entries;
+ return ix;
}
/* Replace od->od_fast_nodes with a new table matching the size of dict's. */
@@ -565,7 +568,7 @@ _odict_resize(PyODictObject *od) {
/* Copy the current nodes into the table. */
_odict_FOREACH(od, node) {
i = _odict_get_index_raw(od, _odictnode_KEY(node),
- _odictnode_HASH(node));
+ _odictnode_HASH(node));
if (i < 0) {
PyMem_FREE(fast_nodes);
return -1;