[pypy-commit] pypy space-iterator-improvements: use length estimate for unpackiterable
fijal
noreply at buildbot.pypy.org
Thu Sep 8 09:24:21 CEST 2011
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: space-iterator-improvements
Changeset: r47157:81a9a624253f
Date: 2011-09-08 09:23 +0200
http://bitbucket.org/pypy/pypy/changeset/81a9a624253f/
Log: use length estimate for unpackiterable
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -8,13 +8,13 @@
from pypy.interpreter.miscutils import ThreadLocals
from pypy.tool.cache import Cache
from pypy.tool.uid import HUGEVAL_BYTES
-from pypy.rlib.objectmodel import we_are_translated
+from pypy.rlib.objectmodel import we_are_translated, newlist
from pypy.rlib.debug import make_sure_not_resized
from pypy.rlib.timer import DummyTimer, Timer
from pypy.rlib.rarithmetic import r_uint
from pypy.rlib import jit
from pypy.tool.sourcetools import func_with_new_name
-import os, sys, py
+import os, sys
__all__ = ['ObjSpace', 'OperationError', 'Wrappable', 'W_Root']
@@ -757,7 +757,15 @@
w_iterator = self.iter(w_iterable)
# If we know the expected length we can preallocate.
if expected_length == -1:
- items = []
+ try:
+ lgt_estimate = self.int_w(self.len(w_iterable))
+ except OperationError:
+ items = []
+ else:
+ try:
+ items = newlist(lgt_estimate)
+ except MemoryError:
+ items = [] # it might have lied
else:
items = [None] * expected_length
idx = 0
More information about the pypy-commit
mailing list