Commits

Antonio Cuni committed c556ee7

not all the constants needs to be initialized (e.g., instances without fields,
empty lists, etc.). This saves a bit of useless "ldsfld xxx; pop" sequences
during the constant initialization phase

Comments (0)

Files changed (3)

pypy/translator/cli/constant.py

         gen.ilasm.opcode('ldftn', signature)
         gen.ilasm.new('instance void class %s::.ctor(object, native int)' % self.delegate_type)
         self.db.const_count.inc('StaticMethod')
-        
-    def initialize_data(self, constgen, gen):
-        return
 
         
 class CLIWeakRefConst(CLIBaseConstMixin, WeakRefConst):
 
     def get_type(self, include_class=True):
         return 'class ' + WEAKREF
+
+    def needs_initialization(self):
+        return bool(self.value)
     
     def initialize_data(self, constgen, gen):
         if self.value is not None:

pypy/translator/jvm/constant.py

         else:
             gen.push_null(jvm.jObject)
 
-    def initialize_data(self, constgen, gen):
-        return
     
 class JVMCustomDictConst(CustomDictConst):
 
             push_constant(self.db, self.value._TYPE, self.value, gen)
         gen.create_weakref(TYPE)
 
-    def initialize_data(self, constgen, gen):
-        gen.pop(ootype.ROOT)
-        return True
+    def needs_initialization(self):
+        return False
     
     
     

pypy/translator/oosupport/constant.py

         """ Iterates through each constant, initializing its data. """
         gen.add_section("Initialize Data Phase")
         for const in all_constants:
+            if not const.needs_initialization():
+                continue
             self._consider_step(gen)
             gen.add_comment("Constant: %s" % const.name)
             self._push_constant_during_init(gen, const)
         assert not self.is_null()
         gen.new(self.value._TYPE)
 
+    def needs_initialization(self):
+        """
+        if True, calls initialize_data
+        """
+        return True
+
     def initialize_data(self, constgen, gen):
         """
         Initializes the internal data.  Begins with a pointer to
             value = self.value._items[f_name]            
             self._record_const_if_complex(FIELD_TYPE, value)
 
+    def needs_initialization(self):
+        return bool(self.value._TYPE._fields)
+
     def initialize_data(self, constgen, gen):
         assert not self.is_null()
         SELFTYPE = self.value._TYPE
 
         return const_list
 
+    def needs_initialization(self):
+        self.const_list = self._sorted_const_list()
+        return bool(self.const_list)
+
     def initialize_data(self, constgen, gen):
         assert not self.is_null()
 
         # Get a list of all the constants we'll need to initialize.
         # I am not clear on why this needs to be sorted, actually,
         # but we sort it.
-        const_list = self._sorted_const_list()
+        const_list = self.const_list
         
         # Push ourself on the stack, and cast to our actual type if it
         # is not the same as our static type
         INSTANCE = self.value._INSTANCE
         gen.getclassobject(INSTANCE)
 
-    def initialize_data(self, constgen, gen):
-        pass
+    def needs_initialization(self):
+        return False
 
 # ______________________________________________________________________
 # List constants
         Void. """
         return self.value._TYPE.ITEM is ootype.Void
 
+    def needs_initialization(self):
+        return bool(self.value._list)
+
     def initialize_data(self, constgen, gen):
         assert not self.is_null()
         SELFTYPE = self.value._TYPE
         Void. """
         return self.value._TYPE.ITEM is ootype.Void
 
+    def needs_initialization(self):
+        return bool(self.value._array)
+
     def initialize_data(self, constgen, gen):
         assert not self.is_null()
         SELFTYPE = self.value._TYPE
             self._record_const_if_complex(self.value._TYPE._KEYTYPE, key)
             self._record_const_if_complex(self.value._TYPE._VALUETYPE, value)
 
+    def needs_initialization(self):
+        return bool(self.value._dict)
+
     def initialize_data(self, constgen, gen):
         assert not self.is_null()
         SELFTYPE = self.value._TYPE
             self.db.pending_function(self.value.graph)
         self.delegate_type = self.db.record_delegate(self.value._TYPE)
 
-    def initialize_data(self, constgen, gen):
-        raise NotImplementedError
+    def needs_initialization(self):
+        return False
 
 # ______________________________________________________________________
 # Weak Reference constants
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.