Commits

Maciej Fijalkowski committed 316f403

part one - try to add jitdriver to unpackiterable that specializes on type
of the iterable

Comments (0)

Files changed (1)

pypy/interpreter/baseobjspace.py

 
 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
     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
                                                       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.
             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: