[pypy-commit] pypy faster-isinstance: Specialize correctly isinstance, isisntance_w and _type_isinstance for the
fijal
noreply at buildbot.pypy.org
Thu Sep 29 00:36:18 CEST 2011
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: faster-isinstance
Changeset: r47664:ca4b24d9cca7
Date: 2011-09-28 19:35 -0300
http://bitbucket.org/pypy/pypy/changeset/ca4b24d9cca7/
Log: Specialize correctly isinstance, isisntance_w and _type_isinstance
for the constant cases. I hope this covers most cases
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -6,6 +6,7 @@
from pypy.interpreter.typedef import default_identity_hash
from pypy.tool.sourcetools import compile2, func_with_new_name
from pypy.module.__builtin__.interp_classobj import W_InstanceObject
+from pypy.rlib.objectmodel import specialize
def object_getattribute(space):
"Utility that returns the app-level descriptor object.__getattribute__."
@@ -507,6 +508,7 @@
def issubtype(space, w_sub, w_type):
return space._type_issubtype(w_sub, w_type)
+ @specialize.arg_or_var(2)
def isinstance(space, w_inst, w_type):
return space.wrap(space._type_isinstance(w_inst, w_type))
diff --git a/pypy/objspace/std/model.py b/pypy/objspace/std/model.py
--- a/pypy/objspace/std/model.py
+++ b/pypy/objspace/std/model.py
@@ -269,11 +269,6 @@
self._typeorder_with_empty_usersubcls = None
- for type, classes in self.typeorder.iteritems():
- if len(classes) == 3:
- # W_Root, AnyXxx and actual object
- type.interplevel_cls = classes[0][0]
-
# ____________________________________________________________
# Prebuilt common integer values
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -7,7 +7,7 @@
from pypy.objspace.std import (builtinshortcut, stdtypedef, frame, model,
transparent, callmethod, proxyobject)
from pypy.objspace.descroperation import DescrOperation, raiseattrerror
-from pypy.rlib.objectmodel import instantiate, r_dict, specialize
+from pypy.rlib.objectmodel import instantiate, r_dict, specialize, is_constant
from pypy.rlib.debug import make_sure_not_resized
from pypy.rlib.rarithmetic import base_int, widen
from pypy.rlib.objectmodel import we_are_translated
@@ -83,6 +83,12 @@
if self.config.objspace.std.withtproxy:
transparent.setup(self)
+ for type, classes in self.model.typeorder.iteritems():
+ if len(classes) == 3:
+ # W_Root, AnyXxx and actual object
+ self.gettypefor(type).interplevel_cls = classes[0][0]
+
+
def get_builtin_types(self):
return self.builtin_types
@@ -567,10 +573,19 @@
return self.wrap(w_sub.issubtype(w_type))
raise OperationError(self.w_TypeError, self.wrap("need type objects"))
+ @specialize.arg_or_var(2)
def _type_isinstance(self, w_inst, w_type):
- if isinstance(w_type, W_TypeObject):
- return self.type(w_inst).issubtype(w_type)
- raise OperationError(self.w_TypeError, self.wrap("need type object"))
+ if not isinstance(w_type, W_TypeObject):
+ raise OperationError(self.w_TypeError,
+ self.wrap("need type object"))
+ if is_constant(w_type):
+ cls = w_type.interplevel_cls
+ if cls is not None:
+ assert w_inst is not None
+ if isinstance(w_inst, cls):
+ return True
+ return self.type(w_inst).issubtype(w_type)
+ @specialize.arg_or_var(2)
def isinstance_w(space, w_inst, w_type):
return space._type_isinstance(w_inst, w_type)
More information about the pypy-commit
mailing list