From 5ce4bd3f4ce955577c46fe8e3c5a8f54b60ce3df Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 27 Jul 2009 05:57:40 -0400 Subject: Cache data strings in libbe.diff.DiffTree. This makes repeated .report() generation from the same tree more efficient. --- libbe/diff.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'libbe') diff --git a/libbe/diff.py b/libbe/diff.py index 59e7c66..decbcf5 100644 --- a/libbe/diff.py +++ b/libbe/diff.py @@ -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): -- cgit