[pypy-svn] r10591 - pypy/dist/pypy/translator

tismer at codespeak.net tismer at codespeak.net
Wed Apr 13 20:07:17 CEST 2005


Author: tismer
Date: Wed Apr 13 20:07:16 2005
New Revision: 10591

Modified:
   pypy/dist/pypy/translator/geninterplevel.py
Log:
optimized list initialization for single values.
Reason: rpystone did masses of zero assignments.

Modified: pypy/dist/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/dist/pypy/translator/geninterplevel.py	(original)
+++ pypy/dist/pypy/translator/geninterplevel.py	Wed Apr 13 20:07:16 2005
@@ -746,12 +746,17 @@
         name = self.uniquename('g%dlist' % len(lis))
         # note that self.latercode led to too late initialization.
         self.register_early(lis, name)
-        self.initcode.append('%s = space.newlist([space.w_None])' % (name,))
+        if lis and min(lis) is max(lis) and min(lis) not in lis:
+            default = min(lis)
+        else:
+            default = None
+        self.initcode.append('%s = space.newlist([%s])' % (name, self.nameof(default)))
         self.initcode.append('%s = space.mul(%s, %s)' % (name, name, self.nameof(len(lis))))
         for i in range(len(lis)):
-            item = self.nameof(lis[i])
-            self.initcode.append('space.setitem(%s, %s, %s);' % (
-                name, self.nameof(i), item))
+            if lis[i] is not default:
+                item = self.nameof(lis[i])
+                self.initcode.append('space.setitem(%s, %s, %s);' % (
+                    name, self.nameof(i), item))
         return name
 
     def nameof_dict(self, dic):



More information about the Pypy-commit mailing list