8000 Merge pull request #46 from alex/patch-1 · ossdev07/msgpack-python@1532eaa · GitHub
[go: up one dir, main page]

Skip to content

Commit 1532eaa

Browse files
committed
Merge pull request msgpack#46 from alex/patch-1
On PyPy, preallocate lists
2 parents 626ae51 + 3f12846 commit 1532eaa

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

msgpack/fallback.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def dict_iteritems(d):
2222
if hasattr(sys, 'pypy_version_info'):
2323
# cStringIO is slow on PyPy, StringIO is faster. However: PyPy's own
2424
# StringBuilder is fastest.
25+
from __pypy__ import newlist_hint
2526
from __pypy__.builders import StringBuilder
2627
USING_STRINGBUILDER = True
2728
class StringIO(object):
@@ -38,6 +39,7 @@ def getvalue(self):
3839
else:
3940
USING_STRINGBUILDER = False
4041
from io import BytesIO as StringIO
42+
newlist_hint = lambda size: []
4143

4244
from msgpack.exceptions import (
4345
BufferFull,
@@ -346,7 +348,7 @@ def _fb_unpack(self, execute=EX_CONSTRUCT, write_bytes=None):
346348
# TODO check whether we need to call `list_hook`
347349
self._fb_unpack(EX_SKIP, write_bytes)
348350
return
349-
ret = []
351+
ret = newlist_hint(n)
350352
for i in xrange(n):
351353
ret.append(self._fb_unpack(EX_CONSTRUCT, write_bytes))
352354
if self._list_hook is not None:

0 commit comments

Comments
 (0)
0