simplfy generated code for static ranges

This commit is contained in:
Tom
2010-07-25 00:49:15 +02:00
parent 6b6beb588c
commit 527af3b69f
2 changed files with 22 additions and 5 deletions

View File

@@ -578,8 +578,12 @@ exports.RangeNode: class RangeNode extends BaseNode
i: o.scope.freeVariable()
pre: "\n${idt}${result} = []; ${vars}"
if @fromNum and @toNum
o.index: i
body: @compileSimple o
if Math.abs(+@fromNum - +@toNum) >= 20
o.index: i
body: @compileSimple o
else
range: if @exclusive then [+@fromNum...+@toNum] else [+@fromNum..+@toNum]
return "[${range.join(', ')}]"
else
clause: "$@fromVar <= $@toVar ?"
body: "var $i = $@fromVar; $clause $i <$@equals $@toVar : $i >$@equals $@toVar; $clause $i += 1 : $i -= 1"