diff options
author | Inada Naoki <songofacandy@gmail.com> | 2022-03-01 23:09:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-01 23:09:28 (GMT) |
commit | 9833bb91e4d5c2606421d9ec2085f5c2dfb6f72c (patch) | |
tree | cae368d226475abbeae93afd07081e78a7539cd9 /Lib/test/test_sys.py | |
parent | 21099fc064c61d59c936a2f6a0db3e07cd5c8de5 (diff) | |
download | cpython-9833bb91e4d5c2606421d9ec2085f5c2dfb6f72c.zip cpython-9833bb91e4d5c2606421d9ec2085f5c2dfb6f72c.tar.gz cpython-9833bb91e4d5c2606421d9ec2085f5c2dfb6f72c.tar.bz2 |
bpo-46845: Reduce dict size when all keys are Unicode (GH-31564)
Diffstat (limited to 'Lib/test/test_sys.py')
-rw-r--r-- | Lib/test/test_sys.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 70768f5..f4deb17 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1346,8 +1346,12 @@ class SizeofTest(unittest.TestCase): check({}.__iter__, size('2P')) # empty dict check({}, size('nQ2P')) - # dict - check({"a": 1}, size('nQ2P') + calcsize(DICT_KEY_STRUCT_FORMAT) + 8 + (8*2//3)*calcsize('n2P')) + # dict (string key) + check({"a": 1}, size('nQ2P') + calcsize(DICT_KEY_STRUCT_FORMAT) + 8 + (8*2//3)*calcsize('2P')) + longdict = {str(i): i for i in range(8)} + check(longdict, size('nQ2P') + calcsize(DICT_KEY_STRUCT_FORMAT) + 16 + (16*2//3)*calcsize('2P')) + # dict (non-string key) + check({1: 1}, size('nQ2P') + calcsize(DICT_KEY_STRUCT_FORMAT) + 8 + (8*2//3)*calcsize('n2P')) longdict = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8} check(longdict, size('nQ2P') + calcsize(DICT_KEY_STRUCT_FORMAT) + 16 + (16*2//3)*calcsize('n2P')) # dictionary-keyview @@ -1506,14 +1510,14 @@ class SizeofTest(unittest.TestCase): ) class newstyleclass(object): pass # Separate block for PyDictKeysObject with 8 keys and 5 entries - check(newstyleclass, s + calcsize(DICT_KEY_STRUCT_FORMAT) + 64 + 42*calcsize("n2P")) + check(newstyleclass, s + calcsize(DICT_KEY_STRUCT_FORMAT) + 64 + 42*calcsize("2P")) # dict with shared keys [newstyleclass() for _ in range(100)] check(newstyleclass().__dict__, size('nQ2P') + self.P) o = newstyleclass() o.a = o.b = o.c = o.d = o.e = o.f = o.g = o.h = 1 # Separate block for PyDictKeysObject with 16 keys and 10 entries - check(newstyleclass, s + calcsize(DICT_KEY_STRUCT_FORMAT) + 64 + 42*calcsize("n2P")) + check(newstyleclass, s + calcsize(DICT_KEY_STRUCT_FORMAT) + 64 + 42*calcsize("2P")) # dict with shared keys check(newstyleclass().__dict__, size('nQ2P') + self.P) # unicode |