Author: Alex Gaynor <[email protected]>
Branch: 
Changeset: r61328:f8fe57996da9
Date: 2013-02-16 10:48 -0800
http://bitbucket.org/pypy/pypy/changeset/f8fe57996da9/

Log:    (alex, arigo) Make sure this value is immutable, otherwise traces
        are suboptimal

diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -53,16 +53,17 @@
         kwargname = None
     return Signature(argnames, varargname, kwargname)
 
+
 class PyCode(eval.Code):
     "CPython-style code objects."
     _immutable_ = True
     _immutable_fields_ = ["co_consts_w[*]", "co_names_w[*]", "co_varnames[*]",
-                          "co_freevars[*]", "co_cellvars[*]"]
+                          "co_freevars[*]", "co_cellvars[*]", 
"_args_as_cellvars[*]"]
 
     def __init__(self, space,  argcount, nlocals, stacksize, flags,
                      code, consts, names, varnames, filename,
                      name, firstlineno, lnotab, freevars, cellvars,
-                     hidden_applevel=False, magic = default_magic):
+                     hidden_applevel=False, magic=default_magic):
         """Initialize a new code object from parameters given by
         the pypy compiler"""
         self.space = space
@@ -89,8 +90,6 @@
 
     def _initialize(self):
         self._init_flags()
-        # Precompute what arguments need to be copied into cellvars
-        self._args_as_cellvars = []
 
         if self.co_cellvars:
             argcount = self.co_argcount
@@ -108,16 +107,22 @@
             # produced by CPython are loaded by PyPy.  Note that CPython
             # contains the following bad-looking nested loops at *every*
             # function call!
-            argvars  = self.co_varnames
+
+            # Precompute what arguments need to be copied into cellvars
+            args_as_cellvars = []
+            argvars = self.co_varnames
             cellvars = self.co_cellvars
             for i in range(len(cellvars)):
                 cellname = cellvars[i]
                 for j in range(argcount):
                     if cellname == argvars[j]:
                         # argument j has the same name as the cell var i
-                        while len(self._args_as_cellvars) <= i:
-                            self._args_as_cellvars.append(-1)   # pad
-                        self._args_as_cellvars[i] = j
+                        while len(args_as_cellvars) <= i:
+                            args_as_cellvars.append(-1)   # pad
+                        args_as_cellvars[i] = j
+            self._args_as_cellvars = args_as_cellvars[:]
+        else:
+            self._args_as_cellvars = []
 
         self._compute_flatcall()
 
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to