[pypy-svn] r23387 - in pypy/dist/pypy: interpreter objspace/std

pedronis at codespeak.net pedronis at codespeak.net
Thu Feb 16 03:55:45 CET 2006


Author: pedronis
Date: Thu Feb 16 03:55:39 2006
New Revision: 23387

Modified:
   pypy/dist/pypy/interpreter/pycode.py
   pypy/dist/pypy/interpreter/pyopcode.py
   pypy/dist/pypy/objspace/std/marshal_impl.py
Log:
make LOAD_GLOBAL slightly faster, 

the improvement is mostly visible in test_create1.test_simple_loop()



Modified: pypy/dist/pypy/interpreter/pycode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pycode.py	(original)
+++ pypy/dist/pypy/interpreter/pycode.py	Thu Feb 16 03:55:39 2006
@@ -95,7 +95,7 @@
         self.co_flags = flags
         self.co_code = code
         self.co_consts_w = consts
-        self.co_names = names
+        self.co_names_w = [space.wrap(aname) for aname in names]
         self.co_varnames = varnames
         self.co_freevars = freevars
         self.co_cellvars = cellvars
@@ -133,6 +133,8 @@
                     except IndexError:
                         break   # all cell vars initialized this way
 
+    co_names = property(lambda self: [self.space.unwrap(w_name) for w_name in self.co_names_w]) # for trace
+
     def signature(self):
         return self._signature
     
@@ -301,7 +303,7 @@
         return space.newtuple(self.co_consts_w)
     
     def fget_co_names(space, self):
-        return space.newtuple([space.wrap(name) for name in self.co_names])
+        return space.newtuple(self.co_names_w)
 
     def fget_co_varnames(space, self):
         return space.newtuple([space.wrap(name) for name in self.co_varnames])
@@ -324,13 +326,17 @@
                     self.co_firstlineno == other.co_firstlineno and
                     self.co_code == other.co_code and
                     len(self.co_consts_w) == len(other.co_consts_w) and
-                    self.co_names == other.co_names and
+                    len(self.co_names_w) == len(other.co_names_w) and
                     self.co_varnames == other.co_varnames and
                     self.co_freevars == other.co_freevars and
                     self.co_cellvars == other.co_cellvars)
         if not areEqual:
             return space.w_False
 
+        for i in range(len(self.co_names_w)):
+            if not space.eq_w(self.co_names_w[i], other.co_names_w[i]):
+                return space.w_False
+
         for i in range(len(self.co_consts_w)):
             if not space.eq_w(self.co_consts_w[i], other.co_consts_w[i]):
                 return space.w_False

Modified: pypy/dist/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyopcode.py	(original)
+++ pypy/dist/pypy/interpreter/pyopcode.py	Thu Feb 16 03:55:39 2006
@@ -102,10 +102,10 @@
         return self.pycode.co_consts_w[index]
 
     def getname_u(self, index):
-        return self.pycode.co_names[index]
+        return self.space.str_w(self.pycode.co_names_w[index])
 
     def getname_w(self, index):
-        return self.space.wrap(self.pycode.co_names[index])
+        return self.pycode.co_names_w[index]
 
 
     ################################################################
@@ -471,25 +471,17 @@
     def LOAD_NAME(f, nameindex):
         if f.w_locals is not f.w_globals:
             w_varname = f.getname_w(nameindex)
-            try:
-                w_value = f.space.getitem(f.w_locals, w_varname)
-            except OperationError, e:
-                if not e.match(f.space, f.space.w_KeyError):
-                    raise
-            else:
+            w_value = f.space.finditem(f.w_locals, w_varname)
+            if w_value is not None:
                 f.valuestack.push(w_value)
                 return
         f.LOAD_GLOBAL(nameindex)    # fall-back
 
     def LOAD_GLOBAL(f, nameindex):
         w_varname = f.getname_w(nameindex)
-        try:
-            w_value = f.space.getitem(f.w_globals, w_varname)
-        except OperationError, e:
-            # catch KeyErrors
-            if not e.match(f.space, f.space.w_KeyError):
-                raise
-            # we got a KeyError, now look in the built-ins
+        w_value = f.space.finditem(f.w_globals, w_varname)
+        if w_value is None:
+            # not in the globals, now look in the built-ins
             varname = f.getname_u(nameindex)
             w_value = f.builtin.getdictvalue(f.space, varname)
             if w_value is None:

Modified: pypy/dist/pypy/objspace/std/marshal_impl.py
==============================================================================
--- pypy/dist/pypy/objspace/std/marshal_impl.py	(original)
+++ pypy/dist/pypy/objspace/std/marshal_impl.py	Thu Feb 16 03:55:39 2006
@@ -377,7 +377,7 @@
     m.atom_str(TYPE_STRING, x.co_code)
     m.start(TYPE_TUPLE)
     m.put_list_w(x.co_consts_w, len(x.co_consts_w))
-    m.atom_strlist(TYPE_TUPLE, TYPE_INTERNED, x.co_names)
+    m.atom_strlist(TYPE_TUPLE, TYPE_INTERNED, [space.str_w(w_name) for w_name in x.co_names_w])
     m.atom_strlist(TYPE_TUPLE, TYPE_INTERNED, x.co_varnames)
     m.atom_strlist(TYPE_TUPLE, TYPE_INTERNED, x.co_freevars)
     m.atom_strlist(TYPE_TUPLE, TYPE_INTERNED, x.co_cellvars)



More information about the Pypy-commit mailing list