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

[Maintenance] performance forEach on range #1992

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GrzegorzBobryk
Copy link
Contributor

First one will create Iterator object, second will not. It was used like that only in tests. But gaining slightly faster tests is also good in my opinion.

- `forEach` function [Performs the given operation on each element of this Iterator.](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/for-each.html).
- `for` loop [A for loop over a range or an array is compiled to an index-based loop that does not create an iterator object.](https://kotlinlang.org/docs/control-flow.html#for-loops)

First one will create `Iterator` object, second will not. It was used like that only in tests. But gaining slightly faster tests is good in my opinion.
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.

1 participant