Use depths array rather than passing array args

Approximately doubles the throughput performance of depthed templates and clears the way for doing recursive path lookups in pathed mode.
This commit is contained in:
kpdecker
2014-08-13 14:11:53 -05:00
parent f6dc5ad716
commit b695aaec7c
2 changed files with 36 additions and 33 deletions
+20 -9
View File
@@ -69,6 +69,8 @@ JavaScriptCompiler.prototype = {
this.compileChildren(environment, options);
this.useDepths = this.useDepths || environment.depths.list.length;
var opcodes = environment.opcodes,
opcode,
i,
@@ -115,6 +117,9 @@ JavaScriptCompiler.prototype = {
if (this.options.data) {
ret.useData = true;
}
if (this.useDepths) {
ret.depths = true;
}
if (!asObject) {
ret.compiler = JSON.stringify(ret.compiler);
@@ -151,8 +156,8 @@ JavaScriptCompiler.prototype = {
var params = ["depth0", "helpers", "partials", "data"];
for(var i=0, l=this.environment.depths.list.length; i<l; i++) {
params.push("depth" + this.environment.depths.list[i]);
if (this.useDepths) {
params.push('depths');
}
// Perform a second pass over the output to merge content when possible
@@ -668,6 +673,8 @@ JavaScriptCompiler.prototype = {
child.name = 'program' + index;
this.context.programs[index] = compiler.compile(child, options, this.context, !this.precompile);
this.context.environments[index] = child;
this.useDepths = this.useDepths || compiler.useDepths;
} else {
child.index = index;
child.name = 'program' + index;
@@ -689,17 +696,17 @@ JavaScriptCompiler.prototype = {
}
var child = this.environment.children[guid],
depths = child.depths.list, depth;
depths = child.depths.list,
useDepths = this.useDepths,
depth;
var programParams = [child.index, 'data'];
for(var i=0, l = depths.length; i<l; i++) {
depth = depths[i];
programParams.push('depth' + (depth - 1));
if (useDepths) {
programParams.push('depths');
}
return (depths.length === 0 ? 'this.program(' : 'this.programWithDepth(') + programParams.join(', ') + ')';
return 'this.program(' + programParams.join(', ') + ')';
},
useRegister: function(name) {
@@ -847,7 +854,11 @@ JavaScriptCompiler.prototype = {
},
contextName: function(context) {
return 'depth' + context;
if (this.useDepths && context) {
return 'depths[' + context + ']';
} else {
return 'depth' + context;
}
},
quotedString: function(str) {