Author: Lars Wassermann <[email protected]>
Branch: 
Changeset: r161:a61885e1f0db
Date: 2013-03-11 00:08 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/a61885e1f0db/

Log:    shrank the execution time of the test for changed methoddicts

diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -191,6 +191,9 @@
             raise NotImplementedError(self.instance_kind)
         return w_new
 
+    def w_methoddict(self):
+        return self.w_self()._fetch(constants.CLASS_METHODDICT_INDEX)
+
     def s_methoddict(self):
         jit.promote(self._s_methoddict.version)
         return self._s_methoddict
@@ -292,9 +295,11 @@
 class MethodDictionaryShadow(AbstractCachingShadow):
 
     _immutable_fields_ = ['invalid?']
+    _attr_ = ['methoddict']
 
     def __init__(self, space, w_self):
         self.invalid = True
+        self.methoddict = {}
         AbstractCachingShadow.__init__(self, space, w_self)
 
     def find_selector(self, w_selector):
@@ -996,4 +1001,3 @@
         self.dependent = dependent
 
     def update(self): pass
-    
\ No newline at end of file
diff --git a/spyvm/test/test_miniimage.py b/spyvm/test/test_miniimage.py
--- a/spyvm/test/test_miniimage.py
+++ b/spyvm/test/test_miniimage.py
@@ -282,7 +282,9 @@
     assert isinstance(s_ctx, shadow.MethodContextShadow)
     assert s_ctx.top().is_same_object(space.w_true)
 
-def test_cached_methoddict_compile():
+def test_cached_methoddict():
+    py.test.skip('Should test the same as test_shadow.test_cached_methoddict, 
as long '
+                'as the implementation of MethodDictionary>>#at:put does not 
change.')
     sourcecode = """fib
                         ^self < 2
                             ifTrue: [ 1 ]
diff --git a/spyvm/test/test_shadow.py b/spyvm/test/test_shadow.py
--- a/spyvm/test/test_shadow.py
+++ b/spyvm/test/test_shadow.py
@@ -227,3 +227,29 @@
     else:
         assert False
 
+def test_cached_methoddict():
+    # create a methoddict
+    foo = model.W_CompiledMethod(0)
+    bar = model.W_CompiledMethod(0)
+    baz = model.W_CompiledMethod(0)
+    methods = {'foo': foo,
+               'bar': bar}
+    w_class = build_smalltalk_class("Demo", 0x90, methods=methods)
+    s_class = w_class.as_class_get_shadow(space)
+    s_methoddict = s_class.s_methoddict()
+    s_methoddict.sync_cache()
+    i = 0
+    key = s_methoddict.w_self()._fetch(constants.METHODDICT_NAMES_INDEX+i)
+    while key is space.w_nil:
+        key = s_methoddict.w_self()._fetch(constants.METHODDICT_NAMES_INDEX+i)
+        i = i + 1
+
+    assert (s_class.lookup(key) is foo.as_compiledmethod_get_shadow(space)
+            or s_class.lookup(key) is bar.as_compiledmethod_get_shadow(space))
+    # change that entry
+    w_array = s_class.w_methoddict()._fetch(constants.METHODDICT_VALUES_INDEX)
+    version = s_methoddict.version
+    w_array.atput0(space, i, baz)
+
+    assert s_class.lookup(key) is baz.as_compiledmethod_get_shadow(space)
+    assert version is not s_methoddict.version
\ No newline at end of file
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to