[pypy-svn] r17814 - pypy/dist/pypy/tool

arigo at codespeak.net arigo at codespeak.net
Sat Sep 24 12:15:01 CEST 2005


Author: arigo
Date: Sat Sep 24 12:14:58 2005
New Revision: 17814

Modified:
   pypy/dist/pypy/tool/unionfind.py
Log:
More profiling-driven optimizations of the translation process.


Modified: pypy/dist/pypy/tool/unionfind.py
==============================================================================
--- pypy/dist/pypy/tool/unionfind.py	(original)
+++ pypy/dist/pypy/tool/unionfind.py	Sat Sep 24 12:14:58 2005
@@ -32,8 +32,15 @@
         return self.root_info.values()
 
     def find_rep(self, obj):
-        ignore, rep, info = self.find(obj)
-        return rep
+        try:
+            # fast path (shortcut for performance reasons)
+            parent = self.link_to_parent[obj]
+            self.root_info[parent]   # may raise KeyError
+            return parent
+        except KeyError:
+            # general case
+            ignore, rep, info = self.find(obj)
+            return rep
 
     def find(self, obj):  # -> new_root, obj, info
         if obj not in self.link_to_parent:



More information about the Pypy-commit mailing list