[pypy-svn] r55408 - pypy/branch/parser-complexity/pypy/interpreter/astcompiler

fijal at codespeak.net fijal at codespeak.net
Thu May 29 22:43:56 CEST 2008


Author: fijal
Date: Thu May 29 22:43:53 2008
New Revision: 55408

Modified:
   pypy/branch/parser-complexity/pypy/interpreter/astcompiler/misc.py
Log:
This speeds up astcompiler quite a bit


Modified: pypy/branch/parser-complexity/pypy/interpreter/astcompiler/misc.py
==============================================================================
--- pypy/branch/parser-complexity/pypy/interpreter/astcompiler/misc.py	(original)
+++ pypy/branch/parser-complexity/pypy/interpreter/astcompiler/misc.py	Thu May 29 22:43:53 2008
@@ -45,11 +45,31 @@
 
     return "_%s%s" % (klass, name)
 
+class Queue(object):
+    def __init__(self, item):
+        self.head = [item]
+        self.tail = []
+
+    def pop(self):
+        if self.head:
+            return self.head.pop()
+        else:
+            for i in range(len(self.tail)-1, -1, -1):
+                self.head.append(self.tail[i])
+            self.tail = []
+            return self.head.pop()
+
+    def extend(self, items):
+        self.tail.extend(items)
+
+    def nonempty(self):
+        return self.tail or self.head
+
 def set_filename(filename, tree):
     """Set the filename attribute to filename on every node in tree"""
-    worklist = [tree]
-    while worklist:
-        node = worklist.pop(0)
+    worklist = Queue(tree)
+    while worklist.nonempty():
+        node = worklist.pop()
         assert isinstance(node, ast.Node)
         node.filename = filename
         worklist.extend(node.getChildNodes())



More information about the Pypy-commit mailing list