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 implements m, w { public final m.b a; @VisibleForTesting public final l> b; @VisibleForTesting /* renamed from: c reason: collision with root package name */ public final l> f437c; public final b0 d; public final Supplier e; public MemoryCacheParams f; public long g = SystemClock.uptimeMillis(); /* compiled from: LruCountingMemoryCache */ public class a implements f { 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 bVar; v vVar = v.this; m.a aVar = this.a; Objects.requireNonNull(vVar); Objects.requireNonNull(aVar); synchronized (vVar) { synchronized (vVar) { z2 = false; AnimatableValueParser.B(aVar.f436c > 0); aVar.f436c--; } 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.f436c == 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 b0Var, w.a aVar, Supplier supplier, m.b bVar) { new WeakHashMap(); this.d = b0Var; this.b = new l<>(new u(this, b0Var)); this.f437c = 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 void k(m.a aVar) { m.b bVar; if (aVar != null && (bVar = aVar.e) != null) { ((c.a) bVar).a(aVar.a, false); } } @Override // c.f.j.c.w public CloseableReference a(K k, CloseableReference closeableReference) { return c(k, closeableReference, this.a); } @Override // c.f.j.c.m public CloseableReference b(K k) { m.a e; boolean z2; CloseableReference closeableReference; Objects.requireNonNull(k); synchronized (this) { e = this.b.e(k); z2 = false; if (e != null) { m.a e2 = this.f437c.e(k); Objects.requireNonNull(e2); if (e2.f436c == 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 c(K k, CloseableReference closeableReference, m.b bVar) { CloseableReference closeableReference2; CloseableReference closeableReference3; boolean z2; Objects.requireNonNull(k); Objects.requireNonNull(closeableReference); m(); synchronized (this) { m.a e = this.b.e(k); m.a e2 = this.f437c.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 aVar = new m.a<>(k, closeableReference, bVar); this.f437c.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> lVar = this.f437c; synchronized (lVar) { containsKey = lVar.b.containsKey(k); } return containsKey; } @Override // c.f.j.c.w public int d(j jVar) { ArrayList> f; ArrayList> f2; synchronized (this) { f = this.b.f(jVar); f2 = this.f437c.f(jVar); h(f2); } i(f2); l(f); m(); j(); return f2.size(); } public synchronized int e() { return this.f437c.a() - this.b.a(); } public synchronized int f() { return this.f437c.b() - this.b.b(); } public final synchronized void g(m.a aVar) { Objects.requireNonNull(aVar); AnimatableValueParser.B(!aVar.d); aVar.d = true; } @Override // c.f.j.c.w public CloseableReference get(K k) { m.a e; m.a aVar; Objects.requireNonNull(k); CloseableReference closeableReference = null; synchronized (this) { e = this.b.e(k); l> lVar = this.f437c; synchronized (lVar) { aVar = lVar.b.get(k); } m.a aVar2 = aVar; if (aVar2 != null) { closeableReference = n(aVar2); } } k(e); m(); j(); return closeableReference; } public final synchronized void h(ArrayList> arrayList) { if (arrayList != null) { Iterator> it = arrayList.iterator(); while (it.hasNext()) { g(it.next()); } } } public final void i(ArrayList> arrayList) { if (arrayList != null) { Iterator> it = arrayList.iterator(); while (it.hasNext()) { CloseableReference.s(o(it.next())); } } } public void j() { ArrayList> p; synchronized (this) { MemoryCacheParams memoryCacheParams = this.f; int min = Math.min(memoryCacheParams.d, memoryCacheParams.b - e()); MemoryCacheParams memoryCacheParams2 = this.f; p = p(min, Math.min(memoryCacheParams2.f2257c, memoryCacheParams2.a - f())); h(p); } i(p); l(p); } public final void l(ArrayList> arrayList) { if (arrayList != null) { Iterator> 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 n(m.a aVar) { synchronized (this) { AnimatableValueParser.B(!aVar.d); aVar.f436c++; } return CloseableReference.G(aVar.b.w(), new a(aVar)); return CloseableReference.G(aVar.b.w(), new a(aVar)); } public final synchronized CloseableReference o(m.a aVar) { Objects.requireNonNull(aVar); return (!aVar.d || aVar.f436c != 0) ? null : aVar.b; } public final synchronized ArrayList> 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> arrayList = new ArrayList<>(); while (true) { if (this.b.a() <= max && this.b.b() <= max2) { return arrayList; } l> 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.f437c.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()))); } } } }