diff --git a/app/src/main/java/com/hippo/ehviewer/coil/MergeInterceptor.kt b/app/src/main/java/com/hippo/ehviewer/coil/MergeInterceptor.kt index 0d23dbea5..bc8e77632 100644 --- a/app/src/main/java/com/hippo/ehviewer/coil/MergeInterceptor.kt +++ b/app/src/main/java/com/hippo/ehviewer/coil/MergeInterceptor.kt @@ -19,6 +19,7 @@ object MergeInterceptor : Interceptor { private val pendingContinuationMap: HashMap>> = hashMapOf() private val pendingContinuationMapLock = Mutex() private val notifyScope = CoroutineScope(Dispatchers.IO + SupervisorJob()) + private val EMPTY_LIST = mutableListOf>() override suspend fun intercept(chain: Interceptor.Chain): ImageResult { val originRequest = chain.request val originListener = originRequest.listener @@ -49,10 +50,11 @@ object MergeInterceptor : Interceptor { pendingContinuationMapLock.lock() val existPendingContinuations = pendingContinuationMap[key] if (existPendingContinuations == null) { - pendingContinuationMap[key] = mutableListOf() + pendingContinuationMap[key] = EMPTY_LIST pendingContinuationMapLock.unlock() } else { - existPendingContinuations.apply { + if (existPendingContinuations === EMPTY_LIST) pendingContinuationMap[key] = mutableListOf() + pendingContinuationMap[key]!!.apply { suspendCancellableCoroutine { continuation -> add(continuation) pendingContinuationMapLock.unlock()