[pypy-commit] lang-smalltalk default: added s_class cache to w_AbstractObjectWithClassReference

lwassermann noreply at buildbot.pypy.org
Tue Mar 12 20:01:24 CET 2013


Author: Lars Wassermann <lars.wassermann at gmail.com>
Branch: 
Changeset: r169:dcc5162f3ac8
Date: 2013-03-12 20:01 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/dcc5162f3ac8/

Log:	added s_class cache to w_AbstractObjectWithClassReference

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -221,11 +221,14 @@
 class W_AbstractObjectWithClassReference(W_AbstractObjectWithIdentityHash):
     """Objects with arbitrary class (ie not CompiledMethod, SmallInteger or
     Float)."""
-    _attrs_ = ['w_class']
+    _attrs_ = ['w_class', 's_class']
+    s_class = None
 
     def __init__(self, w_class):
         if w_class is not None:     # it's None only for testing and space generation
             assert isinstance(w_class, W_PointersObject)
+            if w_class.has_shadow():
+                self.s_class = w_class.as_class_get_shadow(w_class._shadow.space)
         self.w_class = w_class
 
     def getclass(self, space):
@@ -250,11 +253,16 @@
 
     def _become(self, w_other):
         self.w_class, w_other.w_class = w_other.w_class, self.w_class
+        self.s_class, w_other.s_class = w_other.s_class, self.s_class
         W_AbstractObjectWithIdentityHash._become(self, w_other)
 
     def has_class(self):
         return self.w_class is not None
-        
+
+    def shadow_of_my_class(self, space):
+        if self.s_class is None:
+            self.s_class = self.w_class.as_class_get_shadow(space)
+        return self.s_class
 
 class W_PointersObject(W_AbstractObjectWithClassReference):
     """Common object."""
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -644,6 +644,7 @@
         raise PrimitiveFailedError()
 
     w_rcvr.w_class = w_arg.w_class
+    w_rcvr.s_class = w_arg.s_class
 
 # ___________________________________________________________________________
 # Miscellaneous Primitives (120-127)
diff --git a/spyvm/squeakimage.py b/spyvm/squeakimage.py
--- a/spyvm/squeakimage.py
+++ b/spyvm/squeakimage.py
@@ -523,6 +523,7 @@
         w_class = self.g_class.w_object
         assert isinstance(w_class, model.W_PointersObject)
         w_pointersobject.w_class = w_class
+        w_pointersobject.s_class = None
         w_pointersobject.hash = self.chunk.hash12
 
     def fillin_wordsobject(self, w_wordsobject):


More information about the pypy-commit mailing list