peerdb/tripe-newpeers.in (ConfigSection.items): Push more cautiously.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 27 May 2018 12:51:45 +0000 (13:51 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 14 Jun 2018 11:50:38 +0000 (12:50 +0100)
Instead of recording which sections have been visited, record all
sections which have been pushed and avoid pushing them again.  This
reduces pointless stack activity.

peerdb/tripe-newpeers.in

index e7f5d51..fdb9170 100644 (file)
@@ -311,16 +311,16 @@ class ConfigSection (object):
 
     ## Initialize for a depth-first walk of the inheritance graph.
     seen = {}
-    visited = {}
+    visiting = { me.name: True }
     stack = [me]
 
     ## Visit nodes, collecting their keys.  Don't believe the values:
     ## resolving inheritance is too hard to do like this.
     while stack:
       sec = stack.pop()
-      if sec.name in visited: continue
-      visited[sec.name] = True
-      stack += sec._parents()
+      for p in sec._parents():
+        if p.name not in visiting:
+          stack.append(p); visiting[p.name] = True
 
       for key in sec._itemmap.iterkeys():
         if key != '@inherit': seen[key] = None