Cache data strings in libbe.diff.DiffTree.
authorW. Trevor King <wking@drexel.edu>
Mon, 27 Jul 2009 09:57:40 +0000 (05:57 -0400)
committerW. Trevor King <wking@drexel.edu>
Mon, 27 Jul 2009 09:57:40 +0000 (05:57 -0400)
This makes repeated .report() generation from the same tree more
efficient.

libbe/diff.py

index 59e7c6643c3ba8df06c0dc8abfda7f1cf3be98c5..decbcf5c92f10149c56be95943513477618fa832 100644 (file)
@@ -120,12 +120,15 @@ class DiffTree (tree.Tree):
         if part != None:
             root.append(part)
     def data_string(self, depth, indent=True):
+        if hasattr(self, "_cached_data_string"):
+            return self._cached_data_string
         data_string = self.data_string_fn(self.data)
         if indent == True:
             data_string_lines = data_string.splitlines()
             indent = "  "*(depth)
             line_sep = "\n"+indent
             data_string = indent+line_sep.join(data_string_lines)
+        self._cached_data_string = data_string
         return data_string
 
 class Diff (object):