From: W. Trevor King Date: Mon, 27 Jul 2009 09:57:40 +0000 (-0400) Subject: Cache data strings in libbe.diff.DiffTree. X-Git-Tag: 1.0.0~62^2~46^2~9^2~8 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5ce4bd3f4ce955577c46fe8e3c5a8f54b60ce3df;p=be.git Cache data strings in libbe.diff.DiffTree. This makes repeated .report() generation from the same tree more efficient. --- 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):