aboutsummaryrefslogtreecommitdiffstats
path: root/json_diff.py
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-11-21 14:03:56 +0100
committerMatěj Cepl <mcepl@redhat.com>2011-11-21 14:03:56 +0100
commit604cb3ea57788097d058b1d04bbe614b8475b8ac (patch)
treec30e8d5c87197fa5232e6a269040be6da0ec26a7 /json_diff.py
parentcc637aceefac9dbe6239db52012828baf6ae9eea (diff)
downloadjson_diff-604cb3ea57788097d058b1d04bbe614b8475b8ac.tar.gz
Don't use strings, when you can use lists (for output collection)
Maybe a bit of premature optimization, but hopefully it won't hurt.
Diffstat (limited to 'json_diff.py')
-rwxr-xr-xjson_diff.py16
1 files changed, 9 insertions, 7 deletions
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)