cpython: 90572ccda12c (original) (raw)

--- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -299,6 +299,26 @@ class DictTest(unittest.TestCase): x.fail = True self.assertRaises(Exc, d.setdefault, x, [])

+ def test_popitem(self): # dict.popitem() for copymode in -1, +1:

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.2.3 release candi Core and Builtins ----------------- +- Issue #13521: dict.setdefault() now does only one lookup for the given key,

--- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -510,27 +510,16 @@ void _PyObject_GC_UNTRACK(op); } - /* -Internal routine to insert a new item into the table. -Used both by the internal resize routine and by the public insert routine. -Eats a reference to key and one to value. -Returns -1 if an error occurred, or 0 on success. +Internal routine to insert a new item into the table when you have entry object. +Used by insertdict. */ static int -insertdict(register PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject *value) +insertdict_by_entry(register PyDictObject *mp, PyObject *key, Py_hash_t hash,

{ PyObject *old_value;

@@ -553,6 +542,28 @@ insertdict(register PyDictObject mp, Py return 0; } + +/ +Internal routine to insert a new item into the table. +Used both by the internal resize routine and by the public insert routine. +Eats a reference to key and one to value. +Returns -1 if an error occurred, or 0 on success. +*/ +static int +insertdict(register PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject *value) +{

+

+} + /* Internal routine used by dictresize() to insert an item which is known to be absent from the dict. This routine also assumes that @@ -776,39 +787,26 @@ PyDict_GetItemWithError(PyObject op, Py return ep->me_value; } -/ CAUTION: PyDict_SetItem() must guarantee that it won't resize the

{ register PyDictObject *mp;

+/* CAUTION: PyDict_SetItem() must guarantee that it won't resize the

+

+} + int PyDict_DelItem(PyObject *op, PyObject *key) { @@ -1797,9 +1825,9 @@ dict_setdefault(register PyDictObject *m return NULL; val = ep->me_value; if (val == NULL) {