Skip to content
This repository has been archived by the owner on Jul 13, 2020. It is now read-only.

Add SparseArrays forEach extensions #255

Merged
merged 2 commits into from
May 3, 2017

Conversation

deva666
Copy link
Contributor

@deva666 deva666 commented Sep 27, 2016

feature #223

@Dragas
Copy link
Contributor

Dragas commented Oct 29, 2016

In my opinion, it should follow the iterator implementation, not for(i in 0..size()-1), as that would prevent possible discrepancies if the said array modifies itself.
That said, current implementation does seem to be prone to IndexOutOfBoundsException if the former happens by self modification as well as ConcurrentModificationException

@Miha-x64
Copy link
Contributor

Miha-x64 commented Mar 9, 2017

I think this implementation is OK, because SparseArrays have no iterators and thus it will be impossible to check for comodification fast and clearly. Unlike iterators, given extensions do not use any extra allocations, which is much appreciated in Android.
Also:
— you can use 0 until size instead of 0 .. size-1, this is less error-prone and more self-explanatory;
— it is also possible to implement forEachKey and forEachValue;
— there are also SparseArrayCompat and SimpleArrayMap, they could be iterated this way too.

@yanex yanex merged commit bdf3e30 into Kotlin:master May 3, 2017
@yanex
Copy link
Member

yanex commented May 3, 2017

Merged. Thank you!

@yanex yanex added this to the Anko 0.10 milestone May 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants