mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
removing extraneous tempvar declarations from range generation by re-ordering...
This commit is contained in:
29
lib/nodes.js
29
lib/nodes.js
@@ -623,24 +623,23 @@
|
|||||||
vars = this.compileVariables(merge(o, {
|
vars = this.compileVariables(merge(o, {
|
||||||
indent: idt
|
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();
|
i = o.scope.freeVariable();
|
||||||
|
result = o.scope.freeVariable();
|
||||||
pre = ("\n" + (idt) + (result) + " = []; " + (vars));
|
pre = ("\n" + (idt) + (result) + " = []; " + (vars));
|
||||||
if (this.fromNum && this.toNum) {
|
if (this.fromNum && this.toNum) {
|
||||||
if (Math.abs(+this.fromNum - +this.toNum) <= 20) {
|
o.index = i;
|
||||||
range = (function() {
|
body = this.compileSimple(o);
|
||||||
_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);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
clause = ("" + this.fromVar + " <= " + this.toVar + " ?");
|
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");
|
body = ("var " + i + " = " + this.fromVar + "; " + clause + " " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + clause + " " + i + " += 1 : " + i + " -= 1");
|
||||||
|
|||||||
@@ -574,21 +574,20 @@ exports.RangeNode = class RangeNode extends BaseNode
|
|||||||
compileArray: (o) ->
|
compileArray: (o) ->
|
||||||
idt = @idt 1
|
idt = @idt 1
|
||||||
vars = @compileVariables merge o, indent: idt
|
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()
|
result = o.scope.freeVariable()
|
||||||
i = o.scope.freeVariable()
|
|
||||||
pre = "\n#{idt}#{result} = []; #{vars}"
|
pre = "\n#{idt}#{result} = []; #{vars}"
|
||||||
if @fromNum and @toNum
|
if @fromNum and @toNum
|
||||||
if Math.abs(+@fromNum - +@toNum) <= 20
|
o.index = i
|
||||||
range = [+@fromNum..+@toNum]
|
body = @compileSimple o
|
||||||
range.pop() if @exclusive
|
|
||||||
return "[#{ range.join(', ') }]"
|
|
||||||
else
|
|
||||||
o.index = i
|
|
||||||
body = @compileSimple o
|
|
||||||
else
|
else
|
||||||
clause = "#@fromVar <= #@toVar ?"
|
clause = "#@fromVar <= #@toVar ?"
|
||||||
body = "var #i = #@fromVar; #clause #i <#@equals #@toVar : #i >#@equals #@toVar; #clause #i += 1 : #i -= 1"
|
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)"
|
"(function() {#{pre}\n#{idt}for (#body)#post}).call(this)"
|
||||||
|
|
||||||
#### SliceNode
|
#### SliceNode
|
||||||
|
|||||||
Reference in New Issue
Block a user