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 ca63bebe5f
commit 598a63d267
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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
}
}