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

Refactor for-loop to only check for upper or lower bound if direction is known at compile time #399

Open
riederm opened this issue Dec 3, 2021 · 0 comments
Labels
enhancement New feature or request performance

Comments

@riederm
Copy link
Collaborator

riederm commented Dec 3, 2021

A for statement no checks whether the counter x is between startand end. this is handy if you dont really know where you're counting up or down (we dont know if step is positive or negative).

FOR x := start TO end BY step DO
   ...
END_FOR

so we do a check like:
x >= start && x <= end || x >= end && x <= start to accomodate for both situations (start < end -> counting up or start > end -> counting down)

if we know that we count up (or down) at compile time (e.g. if no step is provided, or it is a literal), we can skip several of the checks. when counting up, we only need to check against the x <= end ...

@riederm riederm added refactor internal change, cleanup, code-style-improvement enhancement New feature or request and removed refactor internal change, cleanup, code-style-improvement labels Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request performance
Projects
None yet
Development

No branches or pull requests

2 participants