Skip to content

Commit 0268505

Browse files
zdenkoGeoffreyBooth
authored andcommitted
Optimize 'for-range-by' loop when 'by' is literal number (#5016)
* optimize 'for-range-by' loop when 'by' is literal number * small fix
1 parent 5a43b2d commit 0268505

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lib/coffeescript/nodes.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,12 +1370,15 @@ exports.Range = class Range extends Base
13701370
lowerBound = "#{lt} #{ if known then to else @toVar }"
13711371
upperBound = "#{gt} #{ if known then to else @toVar }"
13721372
condPart =
1373-
if @step?
1374-
"#{stepNotZero} && (#{stepCond} ? #{lowerBound} : #{upperBound})"
1375-
else
1376-
if known
1377-
"#{ if from <= to then lt else gt } #{to}"
1378-
else
1373+
if @step?
1374+
if @stepNum? and @stepNum isnt 0
1375+
if @stepNum > 0 then "#{lowerBound}" else "#{upperBound}"
1376+
else
1377+
"#{stepNotZero} && (#{stepCond} ? #{lowerBound} : #{upperBound})"
1378+
else
1379+
if known
1380+
"#{ if from <= to then lt else gt } #{to}"
1381+
else
13791382
"(#{@fromVar} <= #{@toVar} ? #{lowerBound} : #{upperBound})"
13801383

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

0 commit comments

Comments
 (0)