[LL] CleanableSoftValueCache: Avoid cleanup on already removed values
- The cache guarantees deterministic cleanup on removal, so if the reference has already been removed from the cache, there is no need to clean it up again. - Still, I don't want to guarantee that `SoftValueCleaner` is only invoked once (see its documentation), as soft reference semantics cannot be tested properly in our current test infrastructure. ^KT-61222
This commit is contained in:
committed by
Space Team
parent
f7a0e1f7c1
commit
2b40ef6b05
+6
-2
@@ -61,8 +61,12 @@ class CleanableSoftValueCache<K : Any, V : Any>(
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
ref as SoftReferenceWithCleanup<K, V>
|
||||
|
||||
backingMap.remove(ref.key, ref)
|
||||
ref.performCleanup()
|
||||
val wasRemoved = backingMap.remove(ref.key, ref)
|
||||
|
||||
// If `ref` already wasn't part of the map, it will have been cleaned up by a deterministic removal operation.
|
||||
if (wasRemoved) {
|
||||
ref.performCleanup()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user