From fa0df3671d60bd91b69a6e681fd57893816d8e81 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 8 Jun 2016 10:18:18 +0200 Subject: odict: Remove useless ";" after function definition Fix a "gcc -pendatic" warning. --- Objects/odictobject.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'Objects/odictobject.c') diff --git a/Objects/odictobject.c b/Objects/odictobject.c index dccbb3ec4c..9af0b0eafa 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -1462,7 +1462,7 @@ odict_dealloc(PyODictObject *self) ++tstate->trash_delete_nesting; Py_TRASHCAN_SAFE_END(self) -}; +} /* tp_repr */ @@ -1539,7 +1539,7 @@ Done: Py_XDECREF(pieces); Py_ReprLeave((PyObject *)self); return result; -}; +} /* tp_doc */ @@ -1611,7 +1611,7 @@ odict_richcompare(PyObject *v, PyObject *w, int op) } else { Py_RETURN_NOTIMPLEMENTED; } -}; +} /* tp_iter */ @@ -1619,7 +1619,7 @@ static PyObject * odict_iter(PyODictObject *od) { return odictiter_new(od, _odict_ITER_KEYS); -}; +} /* tp_init */ @@ -1645,7 +1645,7 @@ odict_init(PyObject *self, PyObject *args, PyObject *kwds) Py_DECREF(res); return 0; } -}; +} /* tp_new */ @@ -1720,7 +1720,7 @@ PyTypeObject PyODict_Type = { PyObject * PyODict_New(void) { return odict_new(&PyODict_Type, NULL, NULL); -}; +} static int _PyODict_SetItem_KnownHash(PyObject *od, PyObject *key, PyObject *value, @@ -1738,7 +1738,7 @@ _PyODict_SetItem_KnownHash(PyObject *od, PyObject *key, PyObject *value, } } return res; -}; +} int PyODict_SetItem(PyObject *od, PyObject *key, PyObject *value) @@ -1747,7 +1747,7 @@ PyODict_SetItem(PyObject *od, PyObject *key, PyObject *value) if (hash == -1) return -1; return _PyODict_SetItem_KnownHash(od, key, value, hash); -}; +} int PyODict_DelItem(PyObject *od, PyObject *key) @@ -1760,7 +1760,7 @@ PyODict_DelItem(PyObject *od, PyObject *key) if (res < 0) return -1; return _PyDict_DelItem_KnownHash(od, key, hash); -}; +} /* ------------------------------------------- -- cgit v1.2.1 From 823616bdc22856b5df918a443051ec6ec2e9073c Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 5 Sep 2016 14:50:11 -0700 Subject: Issue #24254: Preserve class attribute definition order. --- Objects/odictobject.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Objects/odictobject.c') diff --git a/Objects/odictobject.c b/Objects/odictobject.c index 14be1cd24a..f0560749be 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -1762,6 +1762,21 @@ PyODict_DelItem(PyObject *od, PyObject *key) return _PyDict_DelItem_KnownHash(od, key, hash); } +PyObject * +_PyODict_KeysAsTuple(PyObject *od) { + Py_ssize_t i = 0; + _ODictNode *node; + PyObject *keys = PyTuple_New(PyODict_Size(od)); + if (keys == NULL) + return NULL; + _odict_FOREACH((PyODictObject *)od, node) { + Py_INCREF(_odictnode_KEY(node)); + PyTuple_SET_ITEM(keys, i, _odictnode_KEY(node)); + i++; + } + return keys; +} + /* ------------------------------------------- * The OrderedDict views (keys/values/items) -- cgit v1.2.1 From 7a1aba85e771486e07e4d1d72bbd8d17ce53e0f1 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 7 Sep 2016 17:40:12 -0700 Subject: 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. --- Objects/odictobject.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'Objects/odictobject.c') diff --git a/Objects/odictobject.c b/Objects/odictobject.c index f0560749be..fe47098b62 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; -- cgit v1.2.1 From 66400b952a8b2a55868cdf326c0d030a25e934bf Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 8 Sep 2016 11:08:30 -0700 Subject: fix spelling --- Objects/odictobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Objects/odictobject.c') diff --git a/Objects/odictobject.c b/Objects/odictobject.c index fe47098b62..4a4cd1e048 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -39,7 +39,7 @@ we've considered: __getitem__(), get(), etc. accordingly. The approach with the least performance impact (time and space) is #2, -mirroring the key order of dict's dk_enties with an array of node pointers. +mirroring the key order of dict's dk_entries with an array of node pointers. While lookdict() and friends (dk_lookup) don't give us the index into the array, we make use of pointer arithmetic to get that index. An alternative would be to refactor lookdict() to provide the index, explicitly exposing -- cgit v1.2.1 From 761928cf31626534ebb81a6326c61b42050ef388 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 8 Sep 2016 15:11:11 -0700 Subject: Issue #24254: Drop cls.__definition_order__. --- Objects/odictobject.c | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'Objects/odictobject.c') diff --git a/Objects/odictobject.c b/Objects/odictobject.c index 4a4cd1e048..5968e3f5d5 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -1765,21 +1765,6 @@ PyODict_DelItem(PyObject *od, PyObject *key) return _PyDict_DelItem_KnownHash(od, key, hash); } -PyObject * -_PyODict_KeysAsTuple(PyObject *od) { - Py_ssize_t i = 0; - _ODictNode *node; - PyObject *keys = PyTuple_New(PyODict_Size(od)); - if (keys == NULL) - return NULL; - _odict_FOREACH((PyODictObject *)od, node) { - Py_INCREF(_odictnode_KEY(node)); - PyTuple_SET_ITEM(keys, i, _odictnode_KEY(node)); - i++; - } - return keys; -} - /* ------------------------------------------- * The OrderedDict views (keys/values/items) -- cgit v1.2.1 From 4db82a225deae98b1f4a25e3fbccb05b94dce3cf Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 9 Sep 2016 11:59:08 -0700 Subject: Issue #27576: Fix call order in OrderedDict.__init__(). --- Objects/odictobject.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'Objects/odictobject.c') diff --git a/Objects/odictobject.c b/Objects/odictobject.c index 5968e3f5d5..22b1f1dfed 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -2356,8 +2356,7 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs) PyObject *other = PyTuple_GET_ITEM(args, 0); /* borrowed reference */ assert(other != NULL); Py_INCREF(other); - if (PyDict_CheckExact(other) || - _PyObject_HasAttrId(other, &PyId_items)) { /* never fails */ + if PyDict_CheckExact(other) { PyObject *items; if (PyDict_CheckExact(other)) items = PyDict_Items(other); @@ -2400,6 +2399,20 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs) if (res != 0 || PyErr_Occurred()) return NULL; } + else if (_PyObject_HasAttrId(other, &PyId_items)) { /* never fails */ + PyObject *items; + if (PyDict_CheckExact(other)) + items = PyDict_Items(other); + else + items = _PyObject_CallMethodId(other, &PyId_items, NULL); + Py_DECREF(other); + if (items == NULL) + return NULL; + res = mutablemapping_add_pairs(self, items); + Py_DECREF(items); + if (res == -1) + return NULL; + } else { res = mutablemapping_add_pairs(self, other); Py_DECREF(other); -- cgit v1.2.1