Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize 'for-range-by' loop when 'by' is literal number #5016

Merged
merged 2 commits into from
Mar 15, 2018

Conversation

zdenko
Copy link
Collaborator

@zdenko zdenko commented Mar 15, 2018

Fixes #5015. Simplify and optimize for-range-by loop when step is a literal number.

for x in [1..a] by 1
# for (x = i = 1, ref = a; i <= ref; x = i += 1)

for x in [a..1] by 1
# for (x = i = ref = a; i <= 1; x = i += 1)

for x in [a..b] by 1
# for (x = i = ref = a, ref1 = b; i <= ref1; x = i += 1)

for x in [1..2] by 1
# for (x = i = 1; i <= 2; x = i += 1)

for x in [1..a] by -1
# for (x = i = 1, ref = a; i >= ref; x = i += -1)

for x in [a..1] by -1
# for (x = i = ref = a; i >= 1; x = i += -1)

for x in [a..b] by -1
# for (x = i = ref = a, ref1 = b; i >= ref1; x = i += -1)

for x in [2..1] by -1
# for (x = i = 2; i >= 1; x = i += -1)

src/nodes.coffee Outdated
"#{ if from <= to then lt else gt } #{to}"
else
if @step?
if @stepNum? and @stepNum != 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isnt

@GeoffreyBooth GeoffreyBooth merged commit 0268505 into jashkenas:master Mar 15, 2018
@GeoffreyBooth GeoffreyBooth mentioned this pull request Mar 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression in generated output when using a fixed range
2 participants