Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of Java 8 method. #924

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions coil-base/src/main/java/coil/memory/WeakMemoryCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.ComponentCallbacks2
import android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW
import android.content.ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN
import android.graphics.Bitmap
import android.os.Build.VERSION.SDK_INT
import android.util.Log
import androidx.annotation.VisibleForTesting
import coil.memory.MemoryCache.Key
Expand Down Expand Up @@ -169,11 +168,7 @@ internal class RealWeakMemoryCache(private val logger: Logger?) : WeakMemoryCach
}
} else {
// Iterate over the list of values and delete individual entries that have been collected.
if (SDK_INT >= 24) {
list.removeIf { it.bitmap.get() == null }
} else {
list.removeIfIndices { it.bitmap.get() == null }
}
list.removeIfIndices { it.bitmap.get() == null }

if (list.isEmpty()) {
iterator.remove()
Expand Down
5 changes: 1 addition & 4 deletions coil-base/src/main/java/coil/util/Collections.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,9 @@ internal inline fun <R, T> List<R>.firstNotNullIndices(transform: (R) -> T?): T?
*/
internal inline fun <T> MutableList<T>.removeIfIndices(predicate: (T) -> Boolean) {
var numDeleted = 0

for (rawIndex in indices) {
val index = rawIndex - numDeleted
val value = get(index)

if (predicate(value)) {
if (predicate(get(index))) {
removeAt(index)
numDeleted++
}
Expand Down