[pypy-svn] r17817 - pypy/dist/pypy/rpython

arigo at codespeak.net arigo at codespeak.net
Sat Sep 24 12:48:55 CEST 2005


Author: arigo
Date: Sat Sep 24 12:48:52 2005
New Revision: 17817

Modified:
   pypy/dist/pypy/rpython/lltype.py
Log:
A specialized version of safe_equal() for performance.


Modified: pypy/dist/pypy/rpython/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltype.py	(original)
+++ pypy/dist/pypy/rpython/lltype.py	Sat Sep 24 12:48:52 2005
@@ -24,7 +24,22 @@
             del seeing[seeingkey]
     return safe
 
-safe_equal = saferecursive(operator.eq, True)
+#safe_equal = saferecursive(operator.eq, True)
+def safe_equal(x, y):
+    # a specialized version for performance
+    try:
+        seeing = TLS.seeing_eq
+    except AttributeError:
+        seeing = TLS.seeing_eq = {}
+    seeingkey = (id(x), id(y))
+    if seeingkey in seeing:
+        return True
+    seeing[seeingkey] = True
+    try:
+        return x == y
+    finally:
+        del seeing[seeingkey]
+
 
 class frozendict(dict):
 



More information about the Pypy-commit mailing list