Issue #28583: PyDict_SetDefault didn't combine split table when needed.

Patch by Xiang Zhang.
This commit is contained in:
INADA Naoki 2016-11-02 18:45:16 +09:00
parent 8567e58ae3
commit 93f26f794d
3 changed files with 67 additions and 17 deletions

View file

@ -851,6 +851,23 @@ class DictTest(unittest.TestCase):
return dicts
@support.cpython_only
def test_splittable_setdefault(self):
"""split table must be combined when setdefault()
breaks insertion order"""
a, b = self.make_shared_key_dict(2)
a['a'] = 1
size_a = sys.getsizeof(a)
a['b'] = 2
b.setdefault('b', 2)
size_b = sys.getsizeof(b)
b['a'] = 1
self.assertGreater(size_b, size_a)
self.assertEqual(list(a), ['x', 'y', 'z', 'a', 'b'])
self.assertEqual(list(b), ['x', 'y', 'z', 'b', 'a'])
@support.cpython_only
def test_splittable_del(self):
"""split table must be combined when del d[k]"""