351 lines
11 KiB
Java
351 lines
11 KiB
Java
package b.f.j.c;
|
|
|
|
import android.os.SystemClock;
|
|
import androidx.annotation.VisibleForTesting;
|
|
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;
|
|
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.java */
|
|
/* loaded from: classes2.dex */
|
|
public class v<K, V> implements m<K, V>, w<K, V> {
|
|
public final m.b<K> a;
|
|
@VisibleForTesting
|
|
|
|
/* renamed from: b reason: collision with root package name */
|
|
public final l<K, m.a<K, V>> f558b;
|
|
@VisibleForTesting
|
|
public final l<K, m.a<K, V>> c;
|
|
public final b0<V> d;
|
|
public final Supplier<MemoryCacheParams> e;
|
|
public MemoryCacheParams f;
|
|
public long g = SystemClock.uptimeMillis();
|
|
public final boolean h;
|
|
public final boolean i;
|
|
|
|
/* compiled from: LruCountingMemoryCache.java */
|
|
/* loaded from: classes2.dex */
|
|
public class a implements f<V> {
|
|
public final /* synthetic */ m.a a;
|
|
|
|
public a(m.a aVar) {
|
|
this.a = aVar;
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:24:0x003d */
|
|
@Override // b.f.d.h.f
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
*/
|
|
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;
|
|
d.B(aVar.c > 0);
|
|
aVar.c--;
|
|
}
|
|
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.c == 0) {
|
|
vVar.f558b.d(aVar.a, aVar);
|
|
z2 = true;
|
|
}
|
|
}
|
|
CloseableReference.s(vVar.o(aVar));
|
|
if (!z2) {
|
|
}
|
|
if (aVar == null) {
|
|
((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, boolean z2, boolean z3) {
|
|
new WeakHashMap();
|
|
this.d = b0Var;
|
|
this.f558b = new l<>(new u(this, b0Var));
|
|
this.c = new l<>(new u(this, b0Var));
|
|
this.e = supplier;
|
|
MemoryCacheParams memoryCacheParams = supplier.get();
|
|
d.y(memoryCacheParams, "mMemoryCacheParamsSupplier returned null");
|
|
this.f = memoryCacheParams;
|
|
this.a = bVar;
|
|
this.h = z2;
|
|
this.i = z3;
|
|
}
|
|
|
|
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 // b.f.j.c.w
|
|
public CloseableReference<V> a(K k, CloseableReference<V> closeableReference) {
|
|
return c(k, closeableReference, this.a);
|
|
}
|
|
|
|
@Override // b.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.f558b.e(k);
|
|
z2 = false;
|
|
if (e != null) {
|
|
m.a<K, V> e2 = this.c.e(k);
|
|
Objects.requireNonNull(e2);
|
|
if (e2.c == 0) {
|
|
z2 = true;
|
|
}
|
|
d.B(z2);
|
|
closeableReference = e2.f555b;
|
|
z2 = true;
|
|
} else {
|
|
closeableReference = null;
|
|
}
|
|
}
|
|
if (z2) {
|
|
k(e);
|
|
}
|
|
return closeableReference;
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:27:0x006f */
|
|
@Override // b.f.j.c.m
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
*/
|
|
public CloseableReference<V> c(K k, CloseableReference<V> closeableReference, m.b<K> bVar) {
|
|
CloseableReference<V> closeableReference2;
|
|
CloseableReference<V> closeableReference3;
|
|
int a2;
|
|
boolean z2;
|
|
Objects.requireNonNull(k);
|
|
Objects.requireNonNull(closeableReference);
|
|
m();
|
|
synchronized (this) {
|
|
m.a<K, V> e = this.f558b.e(k);
|
|
m.a<K, V> e2 = this.c.e(k);
|
|
closeableReference2 = null;
|
|
if (e2 != null) {
|
|
g(e2);
|
|
closeableReference3 = o(e2);
|
|
} else {
|
|
closeableReference3 = null;
|
|
}
|
|
a2 = this.d.a(closeableReference.u());
|
|
synchronized (this) {
|
|
z2 = true;
|
|
if (a2 > this.f.e || e() > this.f.f2868b - 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 = this.h ? new m.a<>(k, closeableReference, bVar, a2) : new m.a<>(k, closeableReference, bVar, -1);
|
|
this.c.d(k, aVar);
|
|
closeableReference2 = n(aVar);
|
|
}
|
|
if (closeableReference3 != null) {
|
|
}
|
|
k(e);
|
|
j();
|
|
return closeableReference2;
|
|
}
|
|
|
|
@Override // b.f.j.c.w
|
|
public synchronized boolean contains(K k) {
|
|
boolean containsKey;
|
|
l<K, m.a<K, V>> lVar = this.c;
|
|
synchronized (lVar) {
|
|
containsKey = lVar.f554b.containsKey(k);
|
|
}
|
|
return containsKey;
|
|
}
|
|
|
|
@Override // b.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.f558b.f(jVar);
|
|
f2 = this.c.f(jVar);
|
|
h(f2);
|
|
}
|
|
i(f2);
|
|
l(f);
|
|
m();
|
|
j();
|
|
return f2.size();
|
|
}
|
|
|
|
public synchronized int e() {
|
|
return this.c.a() - this.f558b.a();
|
|
}
|
|
|
|
public synchronized int f() {
|
|
return this.c.b() - this.f558b.b();
|
|
}
|
|
|
|
public final synchronized void g(m.a<K, V> aVar) {
|
|
Objects.requireNonNull(aVar);
|
|
d.B(!aVar.d);
|
|
aVar.d = true;
|
|
}
|
|
|
|
@Override // b.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.f558b.e(k);
|
|
l<K, m.a<K, V>> lVar = this.c;
|
|
synchronized (lVar) {
|
|
aVar = lVar.f554b.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.f2868b - e());
|
|
MemoryCacheParams memoryCacheParams2 = this.f;
|
|
p = p(min, Math.min(memoryCacheParams2.c, memoryCacheParams2.a - f()));
|
|
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();
|
|
d.y(memoryCacheParams, "mMemoryCacheParamsSupplier returned null");
|
|
this.f = memoryCacheParams;
|
|
}
|
|
}
|
|
|
|
public final synchronized CloseableReference<V> n(m.a<K, V> aVar) {
|
|
synchronized (this) {
|
|
d.B(!aVar.d);
|
|
aVar.c++;
|
|
}
|
|
return CloseableReference.D(aVar.f555b.u(), new a(aVar));
|
|
return CloseableReference.D(aVar.f555b.u(), new a(aVar));
|
|
}
|
|
|
|
public final synchronized CloseableReference<V> o(m.a<K, V> aVar) {
|
|
Objects.requireNonNull(aVar);
|
|
return (!aVar.d || aVar.c != 0) ? null : aVar.f555b;
|
|
}
|
|
|
|
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.f558b.a() <= max && this.f558b.b() <= max2) {
|
|
return null;
|
|
}
|
|
ArrayList<m.a<K, V>> arrayList = new ArrayList<>();
|
|
while (true) {
|
|
if (this.f558b.a() <= max && this.f558b.b() <= max2) {
|
|
break;
|
|
}
|
|
l<K, m.a<K, V>> lVar = this.f558b;
|
|
synchronized (lVar) {
|
|
next = lVar.f554b.isEmpty() ? null : lVar.f554b.keySet().iterator().next();
|
|
}
|
|
if (next != null) {
|
|
this.f558b.e(next);
|
|
arrayList.add(this.c.e(next));
|
|
} else if (this.i) {
|
|
l<K, m.a<K, V>> lVar2 = this.f558b;
|
|
synchronized (lVar2) {
|
|
if (lVar2.f554b.isEmpty()) {
|
|
lVar2.c = 0;
|
|
}
|
|
}
|
|
} else {
|
|
throw new IllegalStateException(String.format("key is null, but exclusiveEntries count: %d, size: %d", Integer.valueOf(this.f558b.a()), Integer.valueOf(this.f558b.b())));
|
|
}
|
|
}
|
|
return arrayList;
|
|
}
|
|
}
|