Author: Maciej Fijalkowski <fij...@gmail.com> Branch: Changeset: r68696:198338979947 Date: 2014-01-16 12:09 +0100 http://bitbucket.org/pypy/pypy/changeset/198338979947/
Log: add a jitdriver to tuple.__contains__ diff --git a/pypy/objspace/std/tupleobject.py b/pypy/objspace/std/tupleobject.py --- a/pypy/objspace/std/tupleobject.py +++ b/pypy/objspace/std/tupleobject.py @@ -27,6 +27,9 @@ 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__ = () @@ -119,13 +122,26 @@ 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 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit