[pypy-commit] pypy length-hint: consult length_hint for unknown length iterables
pjenvey
noreply at buildbot.pypy.org
Thu Apr 5 04:25:58 CEST 2012
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: length-hint
Changeset: r54191:68bdcad461d4
Date: 2012-04-04 19:08 -0700
http://bitbucket.org/pypy/pypy/changeset/68bdcad461d4/
Log: consult length_hint for unknown length iterables
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -826,19 +826,12 @@
# contains a loop (made explicit with the decorator above).
#
# If we can guess the expected length we can preallocate.
+ from pypy.objspace.std.iterobject import length_hint
try:
- lgt_estimate = self.len_w(w_iterable)
- except OperationError, o:
- if (not o.match(self, self.w_AttributeError) and
- not o.match(self, self.w_TypeError)):
- raise
- items = []
- else:
- try:
- items = newlist_hint(lgt_estimate)
- except MemoryError:
- items = [] # it might have lied
- #
+ items = newlist_hint(length_hint(self, w_iterable, 0))
+ except MemoryError:
+ items = [] # it might have lied
+
while True:
try:
w_item = self.next(w_iterator)
More information about the pypy-commit
mailing list