[pypy-svn] pypy default: use an iterative instead of a recursive algorithm here

cfbolz commits-noreply at bitbucket.org
Mon Mar 14 17:38:55 CET 2011


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: 
Changeset: r42618:ac10779c0cf6
Date: 2011-03-14 15:44 +0100
http://bitbucket.org/pypy/pypy/changeset/ac10779c0cf6/

Log:	use an iterative instead of a recursive algorithm here

diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -94,6 +94,10 @@
         return index
 
     def _index(self, selector):
+        while isinstance(self, PlainAttribute):
+            if selector == self.selector:
+                return self.position
+            self = self.back
         return -1
 
     def copy(self, obj):
@@ -274,11 +278,6 @@
             self._copy_attr(obj, new_obj)
         return new_obj
 
-    def _index(self, selector):
-        if selector == self.selector:
-            return self.position
-        return self.back._index(selector)
-
     def copy(self, obj):
         new_obj = self.back.copy(obj)
         self._copy_attr(obj, new_obj)

diff --git a/pypy/objspace/std/test/test_mapdict.py b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -51,6 +51,13 @@
 
     assert aa.get_terminator() is aa.back.back
 
+def test_huge_chain():
+    current = Terminator(space, "cls")
+    for i in range(20000):
+        current = PlainAttribute((str(i), DICT), current)
+    assert current.index(("0", DICT)) == 0
+
+
 def test_search():
     aa = PlainAttribute(("b", DICT), PlainAttribute(("a", DICT), Terminator(None, None)))
     assert aa.search(DICT) is aa


More information about the Pypy-commit mailing list