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
This commit is contained in:
Jorge Martin Espinosa
2023-08-08 10:48:39 +02:00
committed by GitHub
parent 8a0ad443d1
commit c14cf15d4f
2 changed files with 3 additions and 2 deletions

1
changelog.d/1035.bugfix Normal file
View File

@@ -0,0 +1 @@
Use `for` instead of `forEach` in `DefaultDiffCacheInvalidator` to improve performance.

View File

@@ -38,9 +38,9 @@ interface DiffCacheInvalidator<T> {
class DefaultDiffCacheInvalidator<T> : DiffCacheInvalidator<T> {
override fun onChanged(position: Int, count: Int, cache: MutableDiffCache<T>) {
(position until position + count).forEach {
for (i in position until position + count) {
// Invalidate cache
cache[it] = null
cache[i] = null
}
}