From 604cb3ea57788097d058b1d04bbe614b8475b8ac Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Mon, 21 Nov 2011 14:03:56 +0100 Subject: Don't use strings, when you can use lists (for output collection) Maybe a bit of premature optimization, but hopefully it won't hurt. --- json_diff.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'json_diff.py') diff --git a/json_diff.py b/json_diff.py index 4bd8125..cb646f6 100755 --- a/json_diff.py +++ b/json_diff.py @@ -103,23 +103,25 @@ class HTMLFormatter(object): return out_str.strip() def _format_array(self, diff_array, typch, level=0): - out_str = "" + out_str = [] for index in range(len(diff_array)): - out_str += self._format_item(diff_array[index], index, typch, level) - return out_str.strip() + out_str.append(self._format_item(diff_array[index], index, typch, level)) + return ("".join(out_str)).strip() # doesn't have level and neither concept of it, much def _format_dict(self, diff_dict, typch="unknown_change", level=0): - out_str = "" + out_str = [] # For all STYLE_MAP keys which are present in diff_dict for typechange in set(diff_dict.keys()) & INTERNAL_KEYS: - out_str += self._format_dict(diff_dict[typechange], typechange, level) + out_str.append(self._format_dict(diff_dict[typechange], + typechange, level)) # For all other non-internal keys for variable in set(diff_dict.keys()) - INTERNAL_KEYS: - out_str += self._format_item(diff_dict[variable], variable, typch, level) + out_str.append(self._format_item(diff_dict[variable], + variable, typch, level)) - return out_str.strip() + return ("".join(out_str)).strip() def __str__(self): return self._generate_page(self.diff) -- cgit