bpo-44206: Add a version number to dictionary keys (GH-26333) · python/cpython@f8a95df · GitHub
Skip to content

Commit f8a95df

Browse files
authored
bpo-44206: Add a version number to dictionary keys (GH-26333)
* Store log2(size) instead of size in dict-keys. * Use enum instead of function pointer to record kind of keys. * Add version number to dict keys.
1 parent 8994e9c commit f8a95df

7 files changed

Lines changed: 223 additions & 317 deletions

File tree

Include/cpython/dictobject.h

Lines changed: 4 additions & 0 deletions

Lib/test/test_ordered_dict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ def test_sizeof_exact(self):
752752
check = self.check_sizeof
753753

754754
basicsize = size('nQ2P' + '3PnPn2P')
755-
keysize = calcsize('2nP2n')
755+
keysize = calcsize('n2BI2n')
756756

757757
entrysize = calcsize('n2P')
758758
p = calcsize('P')

Lib/test/test_sys.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# strings to intern in test_intern()
2323
INTERN_NUMRUNS = 0
2424

25+
DICT_KEY_STRUCT_FORMAT = 'n2BI2n'
2526

2627
class DisplayHookTest(unittest.TestCase):
2728

@@ -1229,9 +1230,9 @@ def inner():
12291230
# empty dict
12301231
check({}, size('nQ2P'))
12311232
# dict
1232-
check({"a": 1}, size('nQ2P') + calcsize('2nP2n') + 8 + (8*2//3)*calcsize('n2P'))
1233+
check({"a": 1}, size('nQ2P') + calcsize(DICT_KEY_STRUCT_FORMAT) + 8 + (8*2//3)*calcsize('n2P'))
12331234
longdict = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8}
1234-
check(longdict, size('nQ2P') + calcsize('2nP2n') + 16 + (16*2//3)*calcsize('n2P'))
1235+
check(longdict, size('nQ2P') + calcsize(DICT_KEY_STRUCT_FORMAT) + 16 + (16*2//3)*calcsize('n2P'))
12351236
# dictionary-keyview
12361237
check({}.keys(), size('P'))
12371238
# dictionary-valueview
@@ -1385,13 +1386,13 @@ def delx(self): del self.__x
13851386
'5P')
13861387
class newstyleclass(object): pass
13871388
# Separate block for PyDictKeysObject with 8 keys and 5 entries
1388-
check(newstyleclass, s + calcsize("2nP2n0P") + 8 + 5*calcsize("n2P"))
1389+
check(newstyleclass, s + calcsize(DICT_KEY_STRUCT_FORMAT) + 8 + 5*calcsize("n2P"))
13891390
# dict with shared keys
13901391
check(newstyleclass().__dict__, size('nQ2P') + 5*self.P)
13911392
o = newstyleclass()
13921393
o.a = o.b = o.c = o.d = o.e = o.f = o.g = o.h = 1
13931394
# Separate block for PyDictKeysObject with 16 keys and 10 entries
1394-
check(newstyleclass, s + calcsize("2nP2n0P") + 16 + 10*calcsize("n2P"))
1395+
check(newstyleclass, s + calcsize(DICT_KEY_STRUCT_FORMAT) + 16 + 10*calcsize("n2P"))
13951396
# dict with shared keys
13961397
check(newstyleclass().__dict__, size('nQ2P') + 10*self.P)
13971398
# unicode

Objects/dict-common.h

Lines changed: 14 additions & 17 deletions

0 commit comments

Comments
 (0)