summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-02-16 12:08:14 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2013-02-16 12:08:14 -0800
commit3f12846d40e035573993cc9c5195bf3607ee98bb (patch)
tree04da2863d58da9ba384f5e4e92bbe310cb02c639
parent626ae51017cdbf62a2c7b00b338747d1b2070513 (diff)
downloadmsgpack-python-3f12846d40e035573993cc9c5195bf3607ee98bb.tar.gz
On PyPy, preallocate lists
When deserealizing arrays, preallocate the resulting list at the correct size.
-rw-r--r--msgpack/fallback.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/msgpack/fallback.py b/msgpack/fallback.py
index a834229..0016bd1 100644
--- a/msgpack/fallback.py
+++ b/msgpack/fallback.py
@@ -22,6 +22,7 @@ else:
if hasattr(sys, 'pypy_version_info'):
# cStringIO is slow on PyPy, StringIO is faster. However: PyPy's own
# StringBuilder is fastest.
+ from __pypy__ import newlist_hint
from __pypy__.builders import StringBuilder
USING_STRINGBUILDER = True
class StringIO(object):
@@ -38,6 +39,7 @@ if hasattr(sys, 'pypy_version_info'):
else:
USING_STRINGBUILDER = False
from io import BytesIO as StringIO
+ newlist_hint = lambda size: []
from msgpack.exceptions import (
BufferFull,
@@ -346,7 +348,7 @@ class Unpacker(object):
# TODO check whether we need to call `list_hook`
self._fb_unpack(EX_SKIP, write_bytes)
return
- ret = []
+ ret = newlist_hint(n)
for i in xrange(n):
ret.append(self._fb_unpack(EX_CONSTRUCT, write_bytes))
if self._list_hook is not None: