[pypy-commit] pypy default: Move the loop in contains() into a seperate function, so it can be inlined if it doesn't hit the fallback case.
alex_gaynor
noreply at buildbot.pypy.org
Sat May 21 05:08:49 CEST 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r44339:5809a5ace634
Date: 2011-05-20 22:19 -0500
http://bitbucket.org/pypy/pypy/changeset/5809a5ace634/
Log: Move the loop in contains() into a seperate function, so it can be
inlined if it doesn't hit the fallback case.
diff --git a/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
--- a/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
@@ -1709,3 +1709,22 @@
i29 = int_is_true(i28)
guard_true(i29, descr=...)
''')
+
+ def test_python_contains(self):
+ def main():
+ class A(object):
+ def __contains__(self, v):
+ return True
+
+ i = 0
+ a = A()
+ while i < 100:
+ i += i in a # ID: contains
+
+ log = self.run(main, [], threshold=80)
+ loop, = log.loops_by_filename(self.filemath)
+ # XXX: haven't confirmed his is correct, it's probably missing a
+ # few instructions
+ loop.match_by_id("contains", """
+ i1 = int_add(i0, 1)
+ """)
\ No newline at end of file
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -376,6 +376,9 @@
w_descr = space.lookup(w_container, '__contains__')
if w_descr is not None:
return space.get_and_call_function(w_descr, w_container, w_item)
+ return self._contains(w_container, w_item)
+
+ def _contains(self, w_container, w_item):
w_iter = space.iter(w_container)
while 1:
try:
More information about the pypy-commit
mailing list