From: Eric S. Raymond Date: Thu, 18 Sep 2003 09:49:32 +0000 (+0000) Subject: Read cliques only on demand. X-Git-Tag: 2.0~7 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=ededcb83bccd0e363067e153b0766a02d14dca09;p=comparator.git Read cliques only on demand. --- diff --git a/comparator.py b/comparator.py index 4c0ddda..a671859 100644 --- a/comparator.py +++ b/comparator.py @@ -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: diff --git a/filterator b/filterator index 2c4f67b..a03f6f0 100755 --- a/filterator +++ b/filterator @@ -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]: