[pypy-commit] pypy default: improve method calls on oldstyle classes
cfbolz
pypy.commits at gmail.com
Wed Aug 31 17:00:19 EDT 2016
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch:
Changeset: r86796:573ad1ed00c6
Date: 2016-08-31 21:59 +0100
http://bitbucket.org/pypy/pypy/changeset/573ad1ed00c6/
Log: improve method calls on oldstyle classes
diff --git a/pypy/module/__builtin__/interp_classobj.py b/pypy/module/__builtin__/interp_classobj.py
--- a/pypy/module/__builtin__/interp_classobj.py
+++ b/pypy/module/__builtin__/interp_classobj.py
@@ -38,6 +38,8 @@
class W_ClassObject(W_Root):
+ _immutable_fields_ = ['bases_w?[*]', 'w_dict?']
+
def __init__(self, space, w_name, bases, w_dict):
self.name = space.str_w(w_name)
make_sure_not_resized(bases)
@@ -75,6 +77,7 @@
"__bases__ items must be classes")
self.bases_w = bases_w
+ @jit.unroll_safe
def is_subclass_of(self, other):
assert isinstance(other, W_ClassObject)
if self is other:
@@ -313,7 +316,7 @@
# This method ignores the instance dict and the __getattr__.
# Returns None if not found.
assert isinstance(name, str)
- w_value = self.w_class.lookup(space, name)
+ w_value = jit.promote(self.w_class).lookup(space, name)
if w_value is None:
return None
w_descr_get = space.lookup(w_value, '__get__')
diff --git a/pypy/module/pypyjit/test_pypy_c/test_instance.py b/pypy/module/pypyjit/test_pypy_c/test_instance.py
--- a/pypy/module/pypyjit/test_pypy_c/test_instance.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_instance.py
@@ -187,6 +187,43 @@
""")
+ def test_oldstyle_methcall(self):
+ def main():
+ def g(): pass
+ class A:
+ def f(self):
+ return self.x + 1
+ class I(A):
+ pass
+ class J(I):
+ pass
+
+
+ class B(J):
+ def __init__(self, x):
+ self.x = x
+
+ i = 0
+ b = B(1)
+ while i < 1000:
+ g()
+ v = b.f() # ID: meth
+ i += v
+ return i
+
+ log = self.run(main, [], threshold=80)
+ loop, = log.loops_by_filename(self.filepath, is_entry_bridge=True)
+ assert loop.match_by_id('meth',
+ '''
+ guard_nonnull_class(p18, ..., descr=...)
+ p52 = getfield_gc_r(p18, descr=...) # read map
+ guard_value(p52, ConstPtr(ptr53), descr=...)
+ p54 = getfield_gc_r(p18, descr=...) # read class
+ guard_value(p54, ConstPtr(ptr55), descr=...)
+ p56 = force_token() # done
+ ''')
+
+
def test_oldstyle_newstyle_mix(self):
def main():
class A:
More information about the pypy-commit
mailing list