2021-12-21 23:37:30 +00:00
package b.f.j.c ;
2021-06-27 20:44:35 +00:00
import android.os.SystemClock ;
import androidx.annotation.VisibleForTesting ;
2021-12-21 23:37:30 +00:00
import b.c.a.a0.d ;
import b.f.d.d.j ;
import b.f.d.h.f ;
import b.f.j.a.c.c ;
import b.f.j.c.m ;
import b.f.j.c.w ;
2021-06-27 20:44:35 +00:00
import com.facebook.common.internal.Supplier ;
import com.facebook.common.references.CloseableReference ;
import com.facebook.imagepipeline.cache.MemoryCacheParams ;
import java.util.ArrayList ;
import java.util.Iterator ;
import java.util.Objects ;
import java.util.WeakHashMap ;
2022-03-02 20:59:20 +00:00
/* compiled from: LruCountingMemoryCache.java */
2022-04-04 20:51:55 +00:00
/* loaded from: classes.dex */
2021-06-27 20:44:35 +00:00
public class v < K , V > implements m < K , V > , w < K , V > {
public final m . b < K > a ;
@VisibleForTesting
2021-12-21 23:37:30 +00:00
/* renamed from: b reason: collision with root package name */
2022-04-04 20:51:55 +00:00
public final l < K , m . a < K , V > > f560b ;
2021-12-21 23:37:30 +00:00
@VisibleForTesting
public final l < K , m . a < K , V > > c ;
2021-06-27 20:44:35 +00:00
public final b0 < V > d ;
public final Supplier < MemoryCacheParams > e ;
public MemoryCacheParams f ;
public long g = SystemClock . uptimeMillis ( ) ;
2022-01-27 00:50:41 +00:00
public final boolean h ;
public final boolean i ;
2021-06-27 20:44:35 +00:00
2022-03-02 20:59:20 +00:00
/* compiled from: LruCountingMemoryCache.java */
2022-04-04 20:51:55 +00:00
/* loaded from: classes.dex */
2021-06-27 20:44:35 +00:00
public class a implements f < V > {
public final /* synthetic */ m . a a ;
public a ( m . a aVar ) {
this . a = aVar ;
}
2022-03-02 20:59:20 +00:00
/* JADX WARN: Removed duplicated region for block: B:24:0x003d */
2021-12-21 23:37:30 +00:00
@Override // b.f.d.h.f
2022-03-02 20:59:20 +00:00
/ *
Code decompiled incorrectly , please refer to instructions dump .
* /
2021-06-27 20:44:35 +00:00
public void release ( V v ) {
boolean z2 ;
m . b < K > bVar ;
v vVar = v . this ;
m . a < K , V > aVar = this . a ;
Objects . requireNonNull ( vVar ) ;
Objects . requireNonNull ( aVar ) ;
synchronized ( vVar ) {
synchronized ( vVar ) {
z2 = false ;
2021-12-21 23:37:30 +00:00
d . B ( aVar . c > 0 ) ;
aVar . c - - ;
2021-06-27 20:44:35 +00:00
}
CloseableReference . s ( vVar . o ( aVar ) ) ;
if ( ! z2 ) {
aVar = null ;
}
if ( ! ( aVar = = null | | ( bVar = aVar . e ) = = null ) ) {
( ( c . a ) bVar ) . a ( aVar . a , true ) ;
}
vVar . m ( ) ;
vVar . j ( ) ;
}
synchronized ( vVar ) {
2021-12-21 23:37:30 +00:00
if ( ! aVar . d & & aVar . c = = 0 ) {
2022-04-04 20:51:55 +00:00
vVar . f560b . d ( aVar . a , aVar ) ;
2021-06-27 20:44:35 +00:00
z2 = true ;
}
}
CloseableReference . s ( vVar . o ( aVar ) ) ;
if ( ! z2 ) {
}
2022-03-02 20:59:20 +00:00
if ( aVar = = null ) {
( ( c . a ) bVar ) . a ( aVar . a , true ) ;
}
2021-06-27 20:44:35 +00:00
vVar . m ( ) ;
vVar . j ( ) ;
}
}
2022-01-27 00:50:41 +00:00
public v ( b0 < V > b0Var , w . a aVar , Supplier < MemoryCacheParams > supplier , m . b < K > bVar , boolean z2 , boolean z3 ) {
2021-06-27 20:44:35 +00:00
new WeakHashMap ( ) ;
this . d = b0Var ;
2022-04-04 20:51:55 +00:00
this . f560b = new l < > ( new u ( this , b0Var ) ) ;
2021-12-21 23:37:30 +00:00
this . c = new l < > ( new u ( this , b0Var ) ) ;
2021-06-27 20:44:35 +00:00
this . e = supplier ;
MemoryCacheParams memoryCacheParams = supplier . get ( ) ;
2021-10-19 23:48:27 +00:00
d . y ( memoryCacheParams , " mMemoryCacheParamsSupplier returned null " ) ;
2021-06-27 20:44:35 +00:00
this . f = memoryCacheParams ;
this . a = bVar ;
2022-01-27 00:50:41 +00:00
this . h = z2 ;
this . i = z3 ;
2021-06-27 20:44:35 +00:00
}
public static < K , V > void k ( m . a < K , V > aVar ) {
m . b < K > bVar ;
if ( aVar ! = null & & ( bVar = aVar . e ) ! = null ) {
( ( c . a ) bVar ) . a ( aVar . a , false ) ;
}
}
2021-12-21 23:37:30 +00:00
@Override // b.f.j.c.w
2021-06-27 20:44:35 +00:00
public CloseableReference < V > a ( K k , CloseableReference < V > closeableReference ) {
return c ( k , closeableReference , this . a ) ;
}
2021-12-21 23:37:30 +00:00
@Override // b.f.j.c.m
2021-06-27 20:44:35 +00:00
public CloseableReference < V > b ( K k ) {
m . a < K , V > e ;
boolean z2 ;
CloseableReference < V > closeableReference ;
Objects . requireNonNull ( k ) ;
synchronized ( this ) {
2022-04-04 20:51:55 +00:00
e = this . f560b . e ( k ) ;
2021-06-27 20:44:35 +00:00
z2 = false ;
if ( e ! = null ) {
2021-12-21 23:37:30 +00:00
m . a < K , V > e2 = this . c . e ( k ) ;
2021-06-27 20:44:35 +00:00
Objects . requireNonNull ( e2 ) ;
2021-12-21 23:37:30 +00:00
if ( e2 . c = = 0 ) {
2021-06-27 20:44:35 +00:00
z2 = true ;
}
2021-10-19 23:48:27 +00:00
d . B ( z2 ) ;
2022-04-04 20:51:55 +00:00
closeableReference = e2 . f557b ;
2021-06-27 20:44:35 +00:00
z2 = true ;
} else {
closeableReference = null ;
}
}
if ( z2 ) {
k ( e ) ;
}
return closeableReference ;
}
2022-03-02 20:59:20 +00:00
/* JADX WARN: Removed duplicated region for block: B:27:0x006f */
2021-12-21 23:37:30 +00:00
@Override // b.f.j.c.m
2022-03-02 20:59:20 +00:00
/ *
Code decompiled incorrectly , please refer to instructions dump .
* /
2021-06-27 20:44:35 +00:00
public CloseableReference < V > c ( K k , CloseableReference < V > closeableReference , m . b < K > bVar ) {
CloseableReference < V > closeableReference2 ;
CloseableReference < V > closeableReference3 ;
2022-01-27 00:50:41 +00:00
int a2 ;
2021-06-27 20:44:35 +00:00
boolean z2 ;
Objects . requireNonNull ( k ) ;
Objects . requireNonNull ( closeableReference ) ;
m ( ) ;
synchronized ( this ) {
2022-04-04 20:51:55 +00:00
m . a < K , V > e = this . f560b . e ( k ) ;
2021-12-21 23:37:30 +00:00
m . a < K , V > e2 = this . c . e ( k ) ;
2021-06-27 20:44:35 +00:00
closeableReference2 = null ;
if ( e2 ! = null ) {
g ( e2 ) ;
closeableReference3 = o ( e2 ) ;
} else {
closeableReference3 = null ;
}
2022-01-27 00:50:41 +00:00
a2 = this . d . a ( closeableReference . u ( ) ) ;
2021-06-27 20:44:35 +00:00
synchronized ( this ) {
z2 = true ;
2022-04-04 20:51:55 +00:00
if ( a2 > this . f . e | | e ( ) > this . f . f2888b - 1 | | f ( ) > this . f . a - a2 ) {
2021-06-27 20:44:35 +00:00
z2 = false ;
}
}
if ( closeableReference3 ! = null ) {
closeableReference3 . close ( ) ;
}
k ( e ) ;
j ( ) ;
return closeableReference2 ;
}
if ( z2 ) {
2022-01-27 00:50:41 +00:00
m . a < K , V > aVar = this . h ? new m . a < > ( k , closeableReference , bVar , a2 ) : new m . a < > ( k , closeableReference , bVar , - 1 ) ;
2021-12-21 23:37:30 +00:00
this . c . d ( k , aVar ) ;
2021-06-27 20:44:35 +00:00
closeableReference2 = n ( aVar ) ;
}
if ( closeableReference3 ! = null ) {
}
k ( e ) ;
j ( ) ;
return closeableReference2 ;
}
2021-12-21 23:37:30 +00:00
@Override // b.f.j.c.w
2021-06-27 20:44:35 +00:00
public synchronized boolean contains ( K k ) {
boolean containsKey ;
2021-12-21 23:37:30 +00:00
l < K , m . a < K , V > > lVar = this . c ;
2021-06-27 20:44:35 +00:00
synchronized ( lVar ) {
2022-04-04 20:51:55 +00:00
containsKey = lVar . f556b . containsKey ( k ) ;
2021-06-27 20:44:35 +00:00
}
return containsKey ;
}
2021-12-21 23:37:30 +00:00
@Override // b.f.j.c.w
2021-06-27 20:44:35 +00:00
public int d ( j < K > jVar ) {
ArrayList < m . a < K , V > > f ;
ArrayList < m . a < K , V > > f2 ;
synchronized ( this ) {
2022-04-04 20:51:55 +00:00
f = this . f560b . f ( jVar ) ;
2021-12-21 23:37:30 +00:00
f2 = this . c . f ( jVar ) ;
2021-06-27 20:44:35 +00:00
h ( f2 ) ;
}
i ( f2 ) ;
l ( f ) ;
m ( ) ;
j ( ) ;
return f2 . size ( ) ;
}
public synchronized int e ( ) {
2022-04-04 20:51:55 +00:00
return this . c . a ( ) - this . f560b . a ( ) ;
2021-06-27 20:44:35 +00:00
}
public synchronized int f ( ) {
2022-04-04 20:51:55 +00:00
return this . c . b ( ) - this . f560b . b ( ) ;
2021-06-27 20:44:35 +00:00
}
public final synchronized void g ( m . a < K , V > aVar ) {
Objects . requireNonNull ( aVar ) ;
2021-10-19 23:48:27 +00:00
d . B ( ! aVar . d ) ;
2021-06-27 20:44:35 +00:00
aVar . d = true ;
}
2021-12-21 23:37:30 +00:00
@Override // b.f.j.c.w
2021-06-27 20:44:35 +00:00
public CloseableReference < V > get ( K k ) {
m . a < K , V > e ;
m . a < K , V > aVar ;
Objects . requireNonNull ( k ) ;
CloseableReference < V > closeableReference = null ;
synchronized ( this ) {
2022-04-04 20:51:55 +00:00
e = this . f560b . e ( k ) ;
2021-12-21 23:37:30 +00:00
l < K , m . a < K , V > > lVar = this . c ;
2021-06-27 20:44:35 +00:00
synchronized ( lVar ) {
2022-04-04 20:51:55 +00:00
aVar = lVar . f556b . get ( k ) ;
2021-06-27 20:44:35 +00:00
}
m . a < K , V > aVar2 = aVar ;
if ( aVar2 ! = null ) {
closeableReference = n ( aVar2 ) ;
}
}
k ( e ) ;
m ( ) ;
j ( ) ;
return closeableReference ;
}
public final synchronized void h ( ArrayList < m . a < K , V > > arrayList ) {
if ( arrayList ! = null ) {
Iterator < m . a < K , V > > it = arrayList . iterator ( ) ;
while ( it . hasNext ( ) ) {
g ( it . next ( ) ) ;
}
}
}
public final void i ( ArrayList < m . a < K , V > > arrayList ) {
if ( arrayList ! = null ) {
Iterator < m . a < K , V > > it = arrayList . iterator ( ) ;
while ( it . hasNext ( ) ) {
CloseableReference . s ( o ( it . next ( ) ) ) ;
}
}
}
public void j ( ) {
ArrayList < m . a < K , V > > p ;
synchronized ( this ) {
MemoryCacheParams memoryCacheParams = this . f ;
2022-04-04 20:51:55 +00:00
int min = Math . min ( memoryCacheParams . d , memoryCacheParams . f2888b - e ( ) ) ;
2021-06-27 20:44:35 +00:00
MemoryCacheParams memoryCacheParams2 = this . f ;
2021-12-21 23:37:30 +00:00
p = p ( min , Math . min ( memoryCacheParams2 . c , memoryCacheParams2 . a - f ( ) ) ) ;
2021-06-27 20:44:35 +00:00
h ( p ) ;
}
i ( p ) ;
l ( p ) ;
}
public final void l ( ArrayList < m . a < K , V > > arrayList ) {
if ( arrayList ! = null ) {
Iterator < m . a < K , V > > it = arrayList . iterator ( ) ;
while ( it . hasNext ( ) ) {
k ( it . next ( ) ) ;
}
}
}
public final synchronized void m ( ) {
if ( this . g + this . f . f < = SystemClock . uptimeMillis ( ) ) {
this . g = SystemClock . uptimeMillis ( ) ;
MemoryCacheParams memoryCacheParams = this . e . get ( ) ;
2021-10-19 23:48:27 +00:00
d . y ( memoryCacheParams , " mMemoryCacheParamsSupplier returned null " ) ;
2021-06-27 20:44:35 +00:00
this . f = memoryCacheParams ;
}
}
public final synchronized CloseableReference < V > n ( m . a < K , V > aVar ) {
synchronized ( this ) {
2021-10-19 23:48:27 +00:00
d . B ( ! aVar . d ) ;
2021-12-21 23:37:30 +00:00
aVar . c + + ;
2021-06-27 20:44:35 +00:00
}
2022-04-04 20:51:55 +00:00
return CloseableReference . D ( aVar . f557b . u ( ) , new a ( aVar ) ) ;
return CloseableReference . D ( aVar . f557b . u ( ) , new a ( aVar ) ) ;
2021-06-27 20:44:35 +00:00
}
public final synchronized CloseableReference < V > o ( m . a < K , V > aVar ) {
Objects . requireNonNull ( aVar ) ;
2022-04-04 20:51:55 +00:00
return ( ! aVar . d | | aVar . c ! = 0 ) ? null : aVar . f557b ;
2021-06-27 20:44:35 +00:00
}
public final synchronized ArrayList < m . a < K , V > > p ( int i , int i2 ) {
K next ;
int max = Math . max ( i , 0 ) ;
int max2 = Math . max ( i2 , 0 ) ;
2022-04-04 20:51:55 +00:00
if ( this . f560b . a ( ) < = max & & this . f560b . b ( ) < = max2 ) {
2021-06-27 20:44:35 +00:00
return null ;
}
ArrayList < m . a < K , V > > arrayList = new ArrayList < > ( ) ;
while ( true ) {
2022-04-04 20:51:55 +00:00
if ( this . f560b . a ( ) < = max & & this . f560b . b ( ) < = max2 ) {
2022-01-27 00:50:41 +00:00
break ;
2021-06-27 20:44:35 +00:00
}
2022-04-04 20:51:55 +00:00
l < K , m . a < K , V > > lVar = this . f560b ;
2021-06-27 20:44:35 +00:00
synchronized ( lVar ) {
2022-04-04 20:51:55 +00:00
next = lVar . f556b . isEmpty ( ) ? null : lVar . f556b . keySet ( ) . iterator ( ) . next ( ) ;
2021-06-27 20:44:35 +00:00
}
if ( next ! = null ) {
2022-04-04 20:51:55 +00:00
this . f560b . e ( next ) ;
2021-12-21 23:37:30 +00:00
arrayList . add ( this . c . e ( next ) ) ;
2022-01-27 00:50:41 +00:00
} else if ( this . i ) {
2022-04-04 20:51:55 +00:00
l < K , m . a < K , V > > lVar2 = this . f560b ;
2022-01-27 00:50:41 +00:00
synchronized ( lVar2 ) {
2022-04-04 20:51:55 +00:00
if ( lVar2 . f556b . isEmpty ( ) ) {
2022-01-27 00:50:41 +00:00
lVar2 . c = 0 ;
}
}
2021-06-27 20:44:35 +00:00
} else {
2022-04-04 20:51:55 +00:00
throw new IllegalStateException ( String . format ( " key is null, but exclusiveEntries count: %d, size: %d " , Integer . valueOf ( this . f560b . a ( ) ) , Integer . valueOf ( this . f560b . b ( ) ) ) ) ;
2021-06-27 20:44:35 +00:00
}
}
2022-01-27 00:50:41 +00:00
return arrayList ;
2021-06-27 20:44:35 +00:00
}
}