Commit a0761d9a by Miguel Araujo Perez

Redoing concatenation of compiled JSTs

Minor performance improvement, avoid memory relocation every time we
iterate and do a string concatenation. Instead add results to a list and
join them at the end.
parent cac86445
...@@ -79,9 +79,9 @@ class Compressor(object): ...@@ -79,9 +79,9 @@ class Compressor(object):
raise CompressorError("\"%s\" is not a valid variant" % variant) raise CompressorError("\"%s\" is not a valid variant" % variant)
def compile_templates(self, paths): def compile_templates(self, paths):
compiled = "" compiled = []
if not paths: if not paths:
return compiled return ''
namespace = settings.PIPELINE_TEMPLATE_NAMESPACE namespace = settings.PIPELINE_TEMPLATE_NAMESPACE
base_path = self.base_path(paths) base_path = self.base_path(paths)
for path in paths: for path in paths:
...@@ -89,17 +89,17 @@ class Compressor(object): ...@@ -89,17 +89,17 @@ class Compressor(object):
contents = re.sub("\r?\n", "\\\\n", contents) contents = re.sub("\r?\n", "\\\\n", contents)
contents = re.sub("'", "\\'", contents) contents = re.sub("'", "\\'", contents)
name = self.template_name(path, base_path) name = self.template_name(path, base_path)
compiled += "%s['%s'] = %s('%s');\n" % ( compiled.append("%s['%s'] = %s('%s');\n" % (
namespace, namespace,
name, name,
settings.PIPELINE_TEMPLATE_FUNC, settings.PIPELINE_TEMPLATE_FUNC,
contents contents
) ))
compiler = TEMPLATE_FUNC if settings.PIPELINE_TEMPLATE_FUNC == DEFAULT_TEMPLATE_FUNC else "" compiler = TEMPLATE_FUNC if settings.PIPELINE_TEMPLATE_FUNC == DEFAULT_TEMPLATE_FUNC else ""
return "\n".join([ return "\n".join([
"%(namespace)s = %(namespace)s || {};" % {'namespace': namespace}, "%(namespace)s = %(namespace)s || {};" % {'namespace': namespace},
compiler, compiler,
compiled ''.join(compiled)
]) ])
def base_path(self, paths): def base_path(self, paths):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment