[pypy-svn] r28904 - pypy/dist/pypy/objspace/std

pedronis at codespeak.net pedronis at codespeak.net
Sat Jun 17 11:39:32 CEST 2006


Author: pedronis
Date: Sat Jun 17 11:39:30 2006
New Revision: 28904

Modified:
   pypy/dist/pypy/objspace/std/typeobject.py
Log:
this gives a 20%ish speed-up on richards on my office machine with the framework.
notice that in this case, because things are always looked up in the type, the exceptional 
and non-exceptional case have no distinct advantage over each other.

staring at the output of DO_LOG_EXC inspired to try this out.



Modified: pypy/dist/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typeobject.py	(original)
+++ pypy/dist/pypy/objspace/std/typeobject.py	Sat Jun 17 11:39:30 2006
@@ -240,19 +240,17 @@
         return w_self.getdictvalue_w(space, space.str_w(w_attr))
     
     def getdictvalue_w(w_self, space, attr):
-        try:
-            return w_self.dict_w[attr]
-        except KeyError:
-            if w_self.lazyloaders:
-                if attr in w_self.lazyloaders:
-                    w_attr = space.new_interned_str(attr)
-                    loader = w_self.lazyloaders[attr]
-                    del w_self.lazyloaders[attr]
-                    w_value = loader()
-                    if w_value is not None:   # None means no such attribute
-                        w_self.dict_w[attr] = w_value
-                        return w_value
-            return None
+        w_value = w_self.dict_w.get(attr, None)
+        if w_self.lazyloaders and w_value is None:
+            if attr in w_self.lazyloaders:
+                w_attr = space.new_interned_str(attr)
+                loader = w_self.lazyloaders[attr]
+                del w_self.lazyloaders[attr]
+                w_value = loader()
+                if w_value is not None:   # None means no such attribute
+                    w_self.dict_w[attr] = w_value
+                    return w_value
+        return w_value
 
     def lookup(w_self, key):
         # note that this doesn't call __get__ on the result at all



More information about the Pypy-commit mailing list