Skip to content

Commit 598a63d

Browse files
authored
Use for instead of forEach with ranges (#1035)
* Use `for` instead of `forEach` with ranges. `forEach` is several times slower when used with ranges. * Add changelog
1 parent ca63beb commit 598a63d

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

changelog.d/1035.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use `for` instead of `forEach` in `DefaultDiffCacheInvalidator` to improve performance.

libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/diff/DiffCacheInvalidator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ interface DiffCacheInvalidator<T> {
3838
class DefaultDiffCacheInvalidator<T> : DiffCacheInvalidator<T> {
3939

4040
override fun onChanged(position: Int, count: Int, cache: MutableDiffCache<T>) {
41-
(position until position + count).forEach {
41+
for (i in position until position + count) {
4242
// Invalidate cache
43-
cache[it] = null
43+
cache[i] = null
4444
}
4545
}
4646

0 commit comments

Comments
 (0)