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

Remove extra comparison in while loop #552

Merged
merged 1 commit into from
Jan 13, 2020

Conversation

sbrichardson
Copy link
Contributor

@sbrichardson sbrichardson commented Jan 13, 2020

Since seems to be used with string lengths only, a val < 0 isn't possible. Loop will end at 0 naturally. Since the current code is using i-- (vs --i), if i === 0 initially, the while loop won't run. If a number < 0 is expected, I'd propose checking before the loop vs each iteration.

// current
while (i-- > 0) // ...

// proposed
while (i--) // ...

Loop will end at 0 naturally. Since using `i--` (instead of `--i`), if `i` is 0 initially, will skip loop.

```js
while (i--) // ...
while (i-- > 0) // ...
```
@fabiosantoscode
Copy link
Collaborator

It's always a positive number, so this change goes in.

Thanks!

@fabiosantoscode fabiosantoscode merged commit 8bf1033 into terser:master Jan 13, 2020
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.

None yet

2 participants