Last active
March 13, 2023 09:30
-
-
Save Bruce0203/368e2089e273bd7bb2effa48975f3454 to your computer and use it in GitHub Desktop.
performance optimized forEach in Kotlin (exclude LinkedList case)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <T> List<T>.fastForEach(callback: (T) -> Unit) { | |
var n = 0 | |
while (n < size) callback(this[n++]) | |
} | |
inline fun <T> Array<T>.fastForEach(callback: (T) -> Unit) { | |
var n = 0 | |
while (n < size) callback(this[n++]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wtf is this??