stream-lined Node.end_pos()
authorStefan Behnel <scoder@users.berlios.de>
Wed, 11 Jun 2008 15:19:08 +0000 (17:19 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Wed, 11 Jun 2008 15:19:08 +0000 (17:19 +0200)
Cython/Compiler/Nodes.py

index d668b38e692379c0f767f33c485d65dc0cf85783..caf94858de8af048c8b50366e8330302b9292c69 100644 (file)
@@ -153,24 +153,24 @@ class Node(object):
             self.body.annotate(code)
             
     def end_pos(self):
+        if not self.child_attrs:
+            return self.pos
         try:
             return self._end_pos
         except AttributeError:
-            flat = []
+            pos = self.pos
             for attr in self.child_attrs:
                 child = getattr(self, attr)
                 # Sometimes lists, sometimes nodes
                 if child is None:
                     pass
                 elif isinstance(child, list):
-                    flat += child
+                    for c in child:
+                        pos = max(pos, c.end_pos())
                 else:
-                    flat.append(child)
-            if len(flat) == 0:
-                self._end_pos = self.pos
-            else:
-                self._end_pos = max([child.end_pos() for child in flat])
-            return self._end_pos
+                    pos = max(pos, child.end_pos())
+            self._end_pos = pos
+            return pos
 
 
 class BlockNode: