mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 19:34:27 -05:00
optimizing comprehensions source references
This commit is contained in:
18
lib/nodes.js
18
lib/nodes.js
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user