2021-06-27 20:44:35 +00:00
package c.f.j.c ;
import android.os.SystemClock ;
import androidx.annotation.VisibleForTesting ;
import c.f.d.d.j ;
import c.f.d.h.f ;
import c.f.j.a.c.c ;
import c.f.j.c.m ;
import c.f.j.c.w ;
import com.airbnb.lottie.parser.AnimatableValueParser ;
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 ;
/* compiled from: LruCountingMemoryCache */
public class v < K , V > implements m < K , V > , w < K , V > {
public final m . b < K > a ;
@VisibleForTesting
public final l < K , m . a < K , V > > b ;
@VisibleForTesting
/* renamed from: c reason: collision with root package name */
public final l < K , m . a < K , V > > f423c ;
public final b0 < V > d ;
public final Supplier < MemoryCacheParams > e ;
public MemoryCacheParams f ;
public long g = SystemClock . uptimeMillis ( ) ;
/* compiled from: LruCountingMemoryCache */
public class a implements f < V > {
public final /* synthetic */ m . a a ;
public a ( m . a aVar ) {
this . a = aVar ;
}
/* JADX WARNING: Removed duplicated region for block: B:25:0x003d */
@Override // c.f.d.h.f
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 ;
AnimatableValueParser . B ( aVar . f422c > 0 ) ;
aVar . f422c - - ;
}
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 ) {
if ( ! aVar . d & & aVar . f422c = = 0 ) {
vVar . b . d ( aVar . a , aVar ) ;
z2 = true ;
}
}
CloseableReference . s ( vVar . o ( aVar ) ) ;
if ( ! z2 ) {
}
( ( c . a ) bVar ) . a ( aVar . a , true ) ;
vVar . m ( ) ;
vVar . j ( ) ;
}
}
public v ( b0 < V > b0Var , w . a aVar , Supplier < MemoryCacheParams > supplier , m . b < K > bVar ) {
new WeakHashMap ( ) ;
this . d = b0Var ;
this . b = new l < > ( new u ( this , b0Var ) ) ;
this . f423c = new l < > ( new u ( this , b0Var ) ) ;
this . e = supplier ;
MemoryCacheParams memoryCacheParams = supplier . get ( ) ;
AnimatableValueParser . y ( memoryCacheParams , " mMemoryCacheParamsSupplier returned null " ) ;
this . f = memoryCacheParams ;
this . a = bVar ;
}
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 ) ;
}
}
@Override // c.f.j.c.w
public CloseableReference < V > a ( K k , CloseableReference < V > closeableReference ) {
return c ( k , closeableReference , this . a ) ;
}
@Override // c.f.j.c.m
public CloseableReference < V > b ( K k ) {
m . a < K , V > e ;
boolean z2 ;
CloseableReference < V > closeableReference ;
Objects . requireNonNull ( k ) ;
synchronized ( this ) {
e = this . b . e ( k ) ;
z2 = false ;
if ( e ! = null ) {
m . a < K , V > e2 = this . f423c . e ( k ) ;
Objects . requireNonNull ( e2 ) ;
if ( e2 . f422c = = 0 ) {
z2 = true ;
}
AnimatableValueParser . B ( z2 ) ;
closeableReference = e2 . b ;
z2 = true ;
} else {
closeableReference = null ;
}
}
if ( z2 ) {
k ( e ) ;
}
return closeableReference ;
}
/* JADX WARNING: Removed duplicated region for block: B:23:0x0064 */
@Override // c.f.j.c.m
public CloseableReference < V > c ( K k , CloseableReference < V > closeableReference , m . b < K > bVar ) {
CloseableReference < V > closeableReference2 ;
CloseableReference < V > closeableReference3 ;
boolean z2 ;
Objects . requireNonNull ( k ) ;
Objects . requireNonNull ( closeableReference ) ;
m ( ) ;
synchronized ( this ) {
m . a < K , V > e = this . b . e ( k ) ;
m . a < K , V > e2 = this . f423c . e ( k ) ;
closeableReference2 = null ;
if ( e2 ! = null ) {
g ( e2 ) ;
closeableReference3 = o ( e2 ) ;
} else {
closeableReference3 = null ;
}
V w = closeableReference . w ( ) ;
synchronized ( this ) {
int a2 = this . d . a ( w ) ;
z2 = true ;
if ( a2 > this . f . e | | e ( ) > this . f . b - 1 | | f ( ) > this . f . a - a2 ) {
z2 = false ;
}
}
if ( closeableReference3 ! = null ) {
closeableReference3 . close ( ) ;
}
k ( e ) ;
j ( ) ;
return closeableReference2 ;
}
if ( z2 ) {
m . a < K , V > aVar = new m . a < > ( k , closeableReference , bVar ) ;
this . f423c . d ( k , aVar ) ;
closeableReference2 = n ( aVar ) ;
}
if ( closeableReference3 ! = null ) {
}
k ( e ) ;
j ( ) ;
return closeableReference2 ;
}
@Override // c.f.j.c.w
public synchronized boolean contains ( K k ) {
boolean containsKey ;
l < K , m . a < K , V > > lVar = this . f423c ;
synchronized ( lVar ) {
containsKey = lVar . b . containsKey ( k ) ;
}
return containsKey ;
}
@Override // c.f.j.c.w
public int d ( j < K > jVar ) {
ArrayList < m . a < K , V > > f ;
ArrayList < m . a < K , V > > f2 ;
synchronized ( this ) {
f = this . b . f ( jVar ) ;
f2 = this . f423c . f ( jVar ) ;
h ( f2 ) ;
}
i ( f2 ) ;
l ( f ) ;
m ( ) ;
j ( ) ;
return f2 . size ( ) ;
}
public synchronized int e ( ) {
return this . f423c . a ( ) - this . b . a ( ) ;
}
public synchronized int f ( ) {
return this . f423c . b ( ) - this . b . b ( ) ;
}
public final synchronized void g ( m . a < K , V > aVar ) {
Objects . requireNonNull ( aVar ) ;
AnimatableValueParser . B ( ! aVar . d ) ;
aVar . d = true ;
}
@Override // c.f.j.c.w
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 ) {
e = this . b . e ( k ) ;
l < K , m . a < K , V > > lVar = this . f423c ;
synchronized ( lVar ) {
aVar = lVar . b . get ( k ) ;
}
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 ;
int min = Math . min ( memoryCacheParams . d , memoryCacheParams . b - e ( ) ) ;
MemoryCacheParams memoryCacheParams2 = this . f ;
2021-07-04 15:26:29 +00:00
p = p ( min , Math . min ( memoryCacheParams2 . f2175c , 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 ( ) ;
AnimatableValueParser . y ( memoryCacheParams , " mMemoryCacheParamsSupplier returned null " ) ;
this . f = memoryCacheParams ;
}
}
public final synchronized CloseableReference < V > n ( m . a < K , V > aVar ) {
synchronized ( this ) {
AnimatableValueParser . B ( ! aVar . d ) ;
aVar . f422c + + ;
}
return CloseableReference . G ( aVar . b . w ( ) , new a ( aVar ) ) ;
return CloseableReference . G ( aVar . b . w ( ) , new a ( aVar ) ) ;
}
public final synchronized CloseableReference < V > o ( m . a < K , V > aVar ) {
Objects . requireNonNull ( aVar ) ;
return ( ! aVar . d | | aVar . f422c ! = 0 ) ? null : aVar . b ;
}
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 ) ;
if ( this . b . a ( ) < = max & & this . b . b ( ) < = max2 ) {
return null ;
}
ArrayList < m . a < K , V > > arrayList = new ArrayList < > ( ) ;
while ( true ) {
if ( this . b . a ( ) < = max & & this . b . b ( ) < = max2 ) {
return arrayList ;
}
l < K , m . a < K , V > > lVar = this . b ;
synchronized ( lVar ) {
next = lVar . b . isEmpty ( ) ? null : lVar . b . keySet ( ) . iterator ( ) . next ( ) ;
}
if ( next ! = null ) {
this . b . e ( next ) ;
arrayList . add ( this . f423c . e ( next ) ) ;
} else {
throw new IllegalStateException ( String . format ( " key is null, but exclusiveEntries count: %d, size: %d " , Integer . valueOf ( this . b . a ( ) ) , Integer . valueOf ( this . b . b ( ) ) ) ) ;
}
}
}
}