mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Issue #9410: Various optimizations to the pickle module, leading to
speedups up to 4x (depending on the benchmark). Mostly ported from Unladen Swallow; initial patch by Alexandre Vassalotti.
This commit is contained in:
parent
350c7229be
commit
ea99c5c949
5 changed files with 1885 additions and 548 deletions
|
@ -1287,12 +1287,6 @@ def decode_long(data):
|
|||
"""
|
||||
return int.from_bytes(data, byteorder='little', signed=True)
|
||||
|
||||
# Use the faster _pickle if possible
|
||||
try:
|
||||
from _pickle import *
|
||||
except ImportError:
|
||||
Pickler, Unpickler = _Pickler, _Unpickler
|
||||
|
||||
# Shorthands
|
||||
|
||||
def dump(obj, file, protocol=None, *, fix_imports=True):
|
||||
|
@ -1316,6 +1310,12 @@ def loads(s, *, fix_imports=True, encoding="ASCII", errors="strict"):
|
|||
return Unpickler(file, fix_imports=fix_imports,
|
||||
encoding=encoding, errors=errors).load()
|
||||
|
||||
# Use the faster _pickle if possible
|
||||
try:
|
||||
from _pickle import *
|
||||
except ImportError:
|
||||
Pickler, Unpickler = _Pickler, _Unpickler
|
||||
|
||||
# Doctest
|
||||
def _test():
|
||||
import doctest
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue