optimizing comprehensions source references

This commit is contained in:
Jeremy Ashkenas
2010-10-06 21:13:11 -04:00
parent 5605ba32e3
commit d4dac214ab
11 changed files with 70 additions and 86 deletions

View File

@@ -1639,7 +1639,7 @@
return '';
};
ForNode.prototype.compileNode = function(o) {
var body, codeInBody, forPart, guardPart, idt1, index, ivar, lvar, name, namePart, range, ref, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, varPart, vars;
var _ref2, body, codeInBody, forPart, guardPart, idt1, index, ivar, lvar, name, namePart, range, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, varPart, vars;
topLevel = del(o, 'top') && !this.returns;
range = this.source instanceof ValueNode && this.source.base instanceof RangeNode && !this.source.properties.length;
source = range ? this.source.base : this.source;
@@ -1677,16 +1677,12 @@
step: this.step
}));
} else {
svar = this.source.compile(o);
if (IDENTIFIER.test(svar) && scope.check(svar, {
immediate: true
})) {
sourcePart = '';
} else {
ref = scope.freeVariable('ref');
sourcePart = ("" + ref + " = " + svar + ";");
svar = ref;
}
_ref2 = this.source.compileReference(merge(o, {
top: true
}), {
precompile: true
}), sourcePart = _ref2[0], svar = _ref2[1];
sourcePart = sourcePart === svar ? '' : ("" + sourcePart + ";");
namePart = this.pattern ? new AssignNode(this.name, literal("" + svar + "[" + ivar + "]")).compile(merge(o, {
top: true
})) : (name ? ("" + name + " = " + svar + "[" + ivar + "]") : undefined);