[pypy-svn] r68206 - in pypy/trunk/pypy/jit/metainterp: . test

pedronis at codespeak.net pedronis at codespeak.net
Tue Oct 6 16:30:12 CEST 2009


Author: pedronis
Date: Tue Oct  6 16:30:11 2009
New Revision: 68206

Modified:
   pypy/trunk/pypy/jit/metainterp/optimizeopt.py
   pypy/trunk/pypy/jit/metainterp/test/test_optimizeopt.py
Log:
(cfbolz, pedronis): don't make a list of fielddescrs for virtual structs every time


Modified: pypy/trunk/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/optimizeopt.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/optimizeopt.py	Tue Oct  6 16:30:11 2009
@@ -168,11 +168,12 @@
 
 
 class AbstractVirtualStructValue(AbstractVirtualValue):
-    _attrs_ = ('_fields', )
+    _attrs_ = ('_fields', '_cached_sorted_fields')
 
     def __init__(self, optimizer, keybox, source_op=None):
         AbstractVirtualValue.__init__(self, optimizer, keybox, source_op)
         self._fields = av_newdict2()
+        self._cached_sorted_fields = None
 
     def getfield(self, ofs, default):
         return self._fields.get(ofs, default)
@@ -200,12 +201,22 @@
             self._fields = None
         return self.box
 
+    def _get_field_descr_list(self):
+        _cached_sorted_fields = self._cached_sorted_fields
+        if (_cached_sorted_fields is not None and
+            len(self._fields) == len(_cached_sorted_fields)):
+            lst = self._cached_sorted_fields
+        else:
+            lst = self._fields.keys()
+            sort_descrs(lst)
+            self._cached_sorted_fields = lst
+        return lst
+
     def get_args_for_fail(self, modifier):
         if self.box is None and not modifier.is_virtual(self.keybox):
             # modifier.is_virtual() checks for recursion: it is False unless
             # we have already seen the very same keybox
-            lst = self._fields.keys()
-            sort_descrs(lst)
+            lst = self._get_field_descr_list()
             fieldboxes = [self._fields[ofs].get_key_box() for ofs in lst]
             self._make_virtual(modifier, lst, fieldboxes)
             for ofs in lst:

Modified: pypy/trunk/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_optimizeopt.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_optimizeopt.py	Tue Oct  6 16:30:11 2009
@@ -50,6 +50,19 @@
     assert fdescr.rd_virtuals is None
     assert fdescr.rd_consts == []
     assert fdescr.rd_frame_infos == fi
+
+def test_sharing_field_lists_of_virtual():
+    virt1 = optimizeopt.AbstractVirtualStructValue(None, None)
+    lst1 = virt1._get_field_descr_list()
+    assert lst1 == []
+    lst2 = virt1._get_field_descr_list()
+    assert lst1 is lst2
+    virt1.setfield(LLtypeMixin.valuedescr, optimizeopt.OptValue(None))
+    lst1 = virt1._get_field_descr_list()
+    assert lst1 == [LLtypeMixin.valuedescr]
+    lst2 = virt1._get_field_descr_list()
+    assert lst1 is lst2
+
 # ____________________________________________________________
 
 def equaloplists(oplist1, oplist2, strict_fail_args=True, remap={}):



More information about the Pypy-commit mailing list