merged in evilpie's fix for faster small range comprehensions

This commit is contained in:
Jeremy Ashkenas
2010-07-27 23:00:26 -04:00
3 changed files with 26 additions and 7 deletions

View File

@@ -578,8 +578,13 @@ 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
range = [+@fromNum..+@toNum]
range.pop() if @exclusive
return "[#{ range.join(', ') }]"
else
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"