mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-27 15:44:11 +00:00
On PyPy, preallocate lists
When deserealizing arrays, preallocate the resulting list at the correct size.
This commit is contained in:
parent
626ae51017
commit
3f12846d40
1 changed files with 3 additions and 1 deletions
|
|
@ -22,6 +22,7 @@ else:
|
||||||
if hasattr(sys, 'pypy_version_info'):
|
if hasattr(sys, 'pypy_version_info'):
|
||||||
# cStringIO is slow on PyPy, StringIO is faster. However: PyPy's own
|
# cStringIO is slow on PyPy, StringIO is faster. However: PyPy's own
|
||||||
# StringBuilder is fastest.
|
# StringBuilder is fastest.
|
||||||
|
from __pypy__ import newlist_hint
|
||||||
from __pypy__.builders import StringBuilder
|
from __pypy__.builders import StringBuilder
|
||||||
USING_STRINGBUILDER = True
|
USING_STRINGBUILDER = True
|
||||||
class StringIO(object):
|
class StringIO(object):
|
||||||
|
|
@ -38,6 +39,7 @@ if hasattr(sys, 'pypy_version_info'):
|
||||||
else:
|
else:
|
||||||
USING_STRINGBUILDER = False
|
USING_STRINGBUILDER = False
|
||||||
from io import BytesIO as StringIO
|
from io import BytesIO as StringIO
|
||||||
|
newlist_hint = lambda size: []
|
||||||
|
|
||||||
from msgpack.exceptions import (
|
from msgpack.exceptions import (
|
||||||
BufferFull,
|
BufferFull,
|
||||||
|
|
@ -346,7 +348,7 @@ class Unpacker(object):
|
||||||
# TODO check whether we need to call `list_hook`
|
# TODO check whether we need to call `list_hook`
|
||||||
self._fb_unpack(EX_SKIP, write_bytes)
|
self._fb_unpack(EX_SKIP, write_bytes)
|
||||||
return
|
return
|
||||||
ret = []
|
ret = newlist_hint(n)
|
||||||
for i in xrange(n):
|
for i in xrange(n):
|
||||||
ret.append(self._fb_unpack(EX_CONSTRUCT, write_bytes))
|
ret.append(self._fb_unpack(EX_CONSTRUCT, write_bytes))
|
||||||
if self._list_hook is not None:
|
if self._list_hook is not None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue