1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

removing extraneous tempvar declarations from range generation by re-ordering...

This commit is contained in:
Jeremy Ashkenas 2010-07-27 23:39:28 -04:00
parent a4156b71fa
commit 9d1fd38b69
2 changed files with 22 additions and 24 deletions

View file

@ -623,24 +623,23 @@
vars = this.compileVariables(merge(o, {
indent: idt
}));
result = o.scope.freeVariable();
if (this.fromNum && this.toNum && Math.abs(+this.fromNum - +this.toNum) <= 20) {
range = (function() {
_c = [];
for (var _b = +this.fromNum; +this.fromNum <= +this.toNum ? _b <= +this.toNum : _b >= +this.toNum; +this.fromNum <= +this.toNum ? _b += 1 : _b -= 1){ _c.push(_b) };
return _c;
}).call(this);
if (this.exclusive) {
range.pop();
}
return ("[" + (range.join(', ')) + "]");
}
i = o.scope.freeVariable();
result = o.scope.freeVariable();
pre = ("\n" + (idt) + (result) + " = []; " + (vars));
if (this.fromNum && this.toNum) {
if (Math.abs(+this.fromNum - +this.toNum) <= 20) {
range = (function() {
_b = [];
for (var _c = +this.fromNum; +this.fromNum <= +this.toNum ? _c <= +this.toNum : _c >= +this.toNum; +this.fromNum <= +this.toNum ? _c += 1 : _c -= 1){ _b.push(_c) };
return _b;
}).call(this);
if (this.exclusive) {
range.pop();
}
return ("[" + (range.join(', ')) + "]");
} else {
o.index = i;
body = this.compileSimple(o);
}
o.index = i;
body = this.compileSimple(o);
} else {
clause = ("" + this.fromVar + " <= " + this.toVar + " ?");
body = ("var " + i + " = " + this.fromVar + "; " + clause + " " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + clause + " " + i + " += 1 : " + i + " -= 1");

View file

@ -574,21 +574,20 @@ exports.RangeNode = class RangeNode extends BaseNode
compileArray: (o) ->
idt = @idt 1
vars = @compileVariables merge o, indent: idt
if @fromNum and @toNum and Math.abs(+@fromNum - +@toNum) <= 20
range = [+@fromNum..+@toNum]
range.pop() if @exclusive
return "[#{ range.join(', ') }]"
i = o.scope.freeVariable()
result = o.scope.freeVariable()
i = o.scope.freeVariable()
pre = "\n#{idt}#{result} = []; #{vars}"
if @fromNum and @toNum
if Math.abs(+@fromNum - +@toNum) <= 20
range = [+@fromNum..+@toNum]
range.pop() if @exclusive
return "[#{ range.join(', ') }]"
else
o.index = i
body = @compileSimple o
o.index = i
body = @compileSimple o
else
clause = "#@fromVar <= #@toVar ?"
body = "var #i = #@fromVar; #clause #i <#@equals #@toVar : #i >#@equals #@toVar; #clause #i += 1 : #i -= 1"
post = "{ #{result}.push(#i) };\n#{idt}return #result;\n#o.indent"
post = "{ #{result}.push(#i) };\n#{idt}return #result;\n#o.indent"
"(function() {#{pre}\n#{idt}for (#body)#post}).call(this)"
#### SliceNode