[pypy-commit] pypy speedup-unpackiterable: part one - try to add jitdriver to unpackiterable that specializes on type
fijal
noreply at buildbot.pypy.org
Thu Jul 12 20:46:55 CEST 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: speedup-unpackiterable
Changeset: r56041:316f403e7dec
Date: 2012-07-12 20:46 +0200
http://bitbucket.org/pypy/pypy/changeset/316f403e7dec/
Log: part one - try to add jitdriver to unpackiterable that specializes
on type of the iterable
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -20,6 +20,8 @@
UINT_MAX_32_BITS = r_uint(4294967295)
+unpackiterable_driver = jit.JitDriver(greens = ['tp'],
+ reds = ['items', 'w_item', 'w_iterator'])
class W_Root(object):
"""This is the abstract root class of all wrapped objects that live
@@ -224,6 +226,23 @@
def __spacebind__(self, space):
return self
+class W_InterpIterable(W_Root):
+ def __init__(self, space, w_iterable):
+ self.w_iter = space.iter(w_iterable)
+ self.space = space
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ space = self.space
+ try:
+ return space.next(self.w_iter)
+ except OperationError, e:
+ if not e.match(space, space.w_StopIteration):
+ raise
+ raise StopIteration
+
class InternalSpaceCache(Cache):
"""A generic cache for an object space. Arbitrary information can
be attached to the space by defining a function or class 'f' which
@@ -831,6 +850,9 @@
expected_length)
return lst_w[:] # make the resulting list resizable
+ def iteriterable(self, w_iterable):
+ return W_InterpIterable(self, w_iterable)
+
@jit.dont_look_inside
def _unpackiterable_unknown_length(self, w_iterator, w_iterable):
# Unpack a variable-size list of unknown length.
@@ -851,7 +873,13 @@
except MemoryError:
items = [] # it might have lied
#
+ tp = self.type(w_iterator)
+ w_item = None
while True:
+ unpackiterable_driver.jit_merge_point(tp=tp,
+ w_iterator=w_iterator,
+ w_item=w_item,
+ items=items)
try:
w_item = self.next(w_iterator)
except OperationError, e:
More information about the pypy-commit
mailing list