]> thyrsus.com Git - comparator.git/commitdiff
Read cliques only on demand.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 18 Sep 2003 09:49:32 +0000 (09:49 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 18 Sep 2003 09:49:32 +0000 (09:49 +0000)
comparator.py
filterator

index 4c0dddac521b9716e9a354b199c631073c6c9f0f..a671859505ba217f4f0c8b40a54f34085a72363c 100644 (file)
@@ -53,8 +53,12 @@ class CommonReport:
             for assignment in properties.split(", "):
                 (property, value) = assignment.split("=")
                 self.trees[tree][property.strip()] = int(value)
-        # Now read the common-segment stuff
         self.cliques = []
+        # Reading the clique data is slow, so we only do it
+        # on demand.
+
+    def read_matches(self):
+        # Now read the common-segment stuff
         self.files = {}
         locations = []
         while 1:
@@ -77,6 +81,8 @@ class CommonReport:
 
     def extract_text(self, clique):
         "Return text corresponding to the given clique."
+        if self.matches and not self.cliques:
+            self.read_matches()
         text = None
         if self.dir:
             olddir = os.getcwd()
@@ -103,6 +109,8 @@ class CommonReport:
 
     def filter_by_size(self, minsize):
         "Throw out all common segments below a specified size."
+        if self.matches and not self.cliques:
+            self.read_matches()
         filtered = []
         for clique in self.cliques:
             for (file, start, end) in clique:
index 2c4f67bf777a1c7f8e457293ba961ebed9f2e600..a03f6f0aabad1fecc28f100fdcc403546dfc6950 100755 (executable)
@@ -22,6 +22,7 @@ if __name__ == '__main__':
                 rep += " %s=%s," % (key, value)
             sys.stdout.write(rep[:-1] + "\n")
         print 75 * '-'
+        state.read_matches()
         for clique in state.cliques:
             (file, start, end, text) = state.extract_text(clique)
             if start == 1 and end == state.files[file]: