summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-05-28 08:54:10 (GMT)
committerGitHub <noreply@github.com>2021-05-28 08:54:10 (GMT)
commitf8a95df84bcedebc0aa7132b3d1a4e8f000914bc (patch)
treeab5887ed443a0b8f317c4574b4071b76396618d1 /Lib
parent8994e9c2cd775ddf7b0723824da53fe0d7c039ac (diff)
downloadcpython-f8a95df84bcedebc0aa7132b3d1a4e8f000914bc.zip
cpython-f8a95df84bcedebc0aa7132b3d1a4e8f000914bc.tar.gz
cpython-f8a95df84bcedebc0aa7132b3d1a4e8f000914bc.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_ordered_dict.py2
-rw-r--r--Lib/test/test_sys.py9
2 files changed, 6 insertions, 5 deletions
diff --git a/Lib/test/test_ordered_dict.py b/Lib/test/test_ordered_dict.py
index eb40446..d48edb5 100644
--- a/Lib/test/test_ordered_dict.py
+++ b/Lib/test/test_ordered_dict.py
@@ -752,7 +752,7 @@ class CPythonOrderedDictTests(OrderedDictTests, unittest.TestCase):
check = self.check_sizeof
basicsize = size('nQ2P' + '3PnPn2P')
- keysize = calcsize('2nP2n')
+ keysize = calcsize('n2BI2n')
entrysize = calcsize('n2P')
p = calcsize('P')
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 6574c4f..40fb721 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -22,6 +22,7 @@ import warnings
# strings to intern in test_intern()
INTERN_NUMRUNS = 0
+DICT_KEY_STRUCT_FORMAT = 'n2BI2n'
class DisplayHookTest(unittest.TestCase):
@@ -1229,9 +1230,9 @@ class SizeofTest(unittest.TestCase):
# empty dict
check({}, size('nQ2P'))
# dict
- check({"a": 1}, size('nQ2P') + calcsize('2nP2n') + 8 + (8*2//3)*calcsize('n2P'))
+ check({"a": 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('2nP2n') + 16 + (16*2//3)*calcsize('n2P'))
+ check(longdict, size('nQ2P') + calcsize(DICT_KEY_STRUCT_FORMAT) + 16 + (16*2//3)*calcsize('n2P'))
# dictionary-keyview
check({}.keys(), size('P'))
# dictionary-valueview
@@ -1385,13 +1386,13 @@ class SizeofTest(unittest.TestCase):
'5P')
class newstyleclass(object): pass
# Separate block for PyDictKeysObject with 8 keys and 5 entries
- check(newstyleclass, s + calcsize("2nP2n0P") + 8 + 5*calcsize("n2P"))
+ check(newstyleclass, s + calcsize(DICT_KEY_STRUCT_FORMAT) + 8 + 5*calcsize("n2P"))
# dict with shared keys
check(newstyleclass().__dict__, size('nQ2P') + 5*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("2nP2n0P") + 16 + 10*calcsize("n2P"))
+ check(newstyleclass, s + calcsize(DICT_KEY_STRUCT_FORMAT) + 16 + 10*calcsize("n2P"))
# dict with shared keys
check(newstyleclass().__dict__, size('nQ2P') + 10*self.P)
# unicode