Commits

Maciej Fijalkowski committed 1983389

add a jitdriver to tuple.__contains__

  • Participants
  • Parent commits 14ff99b

Comments (0)

Files changed (1)

pypy/objspace/std/tupleobject.py

             jit.loop_unrolling_heuristic(other, other.length(), UNROLL_CUTOFF))
 
 
+contains_jmp = jit.JitDriver(greens = [], reds = 'auto',
+                             name = 'tuple.contains')
+
 class W_AbstractTupleObject(W_Root):
     __slots__ = ()
 
     descr_gt = _make_tuple_comparison('gt')
     descr_ge = _make_tuple_comparison('ge')
 
-    @jit.look_inside_iff(lambda self, _1, _2: _unroll_condition(self))
     def descr_contains(self, space, w_obj):
+        if _unroll_condition(self):
+            return self._descr_contains_unroll_safe(space, w_obj)
+        else:
+            return self._descr_contains_jmp(space, w_obj)
+
+    @jit.unroll_safe
+    def _descr_contains_unroll_safe(self, space, w_obj):
         for w_item in self.tolist():
             if space.eq_w(w_item, w_obj):
                 return space.w_True
         return space.w_False
 
+    def _descr_contains_jmp(self, space, w_obj):
+        for w_item in self.tolist():
+            contains_jmp.jit_merge_point()
+            if space.eq_w(w_item, w_obj):
+                return space.w_True
+        return space.w_False
+
     def descr_add(self, space, w_other):
         if not isinstance(w_other, W_AbstractTupleObject):
             return space.w_NotImplemented