diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-01-11 11:03:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-11 11:03:20 (GMT) |
commit | 0a2da50e1867831251fad75377d0f10713eb6301 (patch) | |
tree | 4a4f07b2488a4eed222060dc45a05430340a0ad3 /Lib/test/pickletester.py | |
parent | cb3ae5588bd7733e76dc09277bb7626652d9bb64 (diff) | |
download | cpython-0a2da50e1867831251fad75377d0f10713eb6301.zip cpython-0a2da50e1867831251fad75377d0f10713eb6301.tar.gz cpython-0a2da50e1867831251fad75377d0f10713eb6301.tar.bz2 |
bpo-31993: Do not create frames for large bytes and str objects (#5114)
when serialize into memory buffer with C pickle implementations.
This optimization already is performed when serialize into memory
with Python pickle implementations or into a file with both
implementations.
Diffstat (limited to 'Lib/test/pickletester.py')
-rw-r--r-- | Lib/test/pickletester.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 5d983eb..f4e3f81 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -2097,20 +2097,21 @@ class AbstractPickleTests(unittest.TestCase): N = 1024 * 1024 obj = [b'x' * N, b'y' * N, 'z' * N] for proto in range(4, pickle.HIGHEST_PROTOCOL + 1): - for fast in [True, False]: + for fast in [False, True]: with self.subTest(proto=proto, fast=fast): - if hasattr(self, 'pickler'): + if not fast: + # fast=False by default. + # This covers in-memory pickling with pickle.dumps(). + pickled = self.dumps(obj, proto) + else: + # Pickler is required when fast=True. + if not hasattr(self, 'pickler'): + continue buf = io.BytesIO() pickler = self.pickler(buf, protocol=proto) pickler.fast = fast pickler.dump(obj) pickled = buf.getvalue() - elif fast: - continue - else: - # Fallback to self.dumps when fast=False and - # self.pickler is not available. - pickled = self.dumps(obj, proto) unpickled = self.loads(pickled) # More informative error message in case of failure. self.assertEqual([len(x) for x in obj], |