mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
Issue #28583: PyDict_SetDefault didn't combine split table when needed.
Patch by Xiang Zhang.
This commit is contained in:
parent
8567e58ae3
commit
93f26f794d
3 changed files with 67 additions and 17 deletions
|
|
@ -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]"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue