Skip to content

Commit

Permalink
Optimize 'for-range-by' loop when 'by' is literal number (#5016)
Browse files Browse the repository at this point in the history
* optimize 'for-range-by' loop when 'by' is literal number

* small fix
  • Loading branch information
zdenko authored and GeoffreyBooth committed Mar 15, 2018
1 parent 5a43b2d commit 0268505
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/coffeescript/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1370,12 +1370,15 @@ exports.Range = class Range extends Base
lowerBound = "#{lt} #{ if known then to else @toVar }"
upperBound = "#{gt} #{ if known then to else @toVar }"
condPart =
if @step?
"#{stepNotZero} && (#{stepCond} ? #{lowerBound} : #{upperBound})"
else
if known
"#{ if from <= to then lt else gt } #{to}"
else
if @step?
if @stepNum? and @stepNum isnt 0
if @stepNum > 0 then "#{lowerBound}" else "#{upperBound}"
else
"#{stepNotZero} && (#{stepCond} ? #{lowerBound} : #{upperBound})"
else
if known
"#{ if from <= to then lt else gt } #{to}"
else
"(#{@fromVar} <= #{@toVar} ? #{lowerBound} : #{upperBound})"

cond = if @stepVar then "#{@stepVar} > 0" else "#{@fromVar} <= #{@toVar}"
Expand Down

0 comments on commit 0268505

Please sign in to comment.