package t1; import android.util.Log; import java.util.HashMap; import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; /* loaded from: classes.dex */ public final class i implements t1.b { /* renamed from: a, reason: collision with root package name */ private final g f14276a = new g(); /* renamed from: b, reason: collision with root package name */ private final b f14277b = new b(); /* renamed from: c, reason: collision with root package name */ private final Map f14278c = new HashMap(); /* renamed from: d, reason: collision with root package name */ private final Map f14279d = new HashMap(); /* renamed from: e, reason: collision with root package name */ private final int f14280e; /* renamed from: f, reason: collision with root package name */ private int f14281f; private static final class a implements m { /* renamed from: a, reason: collision with root package name */ private final b f14282a; /* renamed from: b, reason: collision with root package name */ int f14283b; /* renamed from: c, reason: collision with root package name */ private Class f14284c; a(b bVar) { this.f14282a = bVar; } @Override // t1.m public void a() { this.f14282a.c(this); } void b(int i10, Class cls) { this.f14283b = i10; this.f14284c = cls; } public boolean equals(Object obj) { if (!(obj instanceof a)) { return false; } a aVar = (a) obj; return this.f14283b == aVar.f14283b && this.f14284c == aVar.f14284c; } public int hashCode() { int i10 = this.f14283b * 31; Class cls = this.f14284c; return i10 + (cls != null ? cls.hashCode() : 0); } public String toString() { return "Key{size=" + this.f14283b + "array=" + this.f14284c + '}'; } } private static final class b extends c { b() { } /* JADX INFO: Access modifiers changed from: protected */ @Override // t1.c /* renamed from: d, reason: merged with bridge method [inline-methods] */ public a a() { return new a(this); } a e(int i10, Class cls) { a aVar = (a) b(); aVar.b(i10, cls); return aVar; } } public i(int i10) { this.f14280e = i10; } private void f(int i10, Class cls) { NavigableMap m10 = m(cls); Integer num = (Integer) m10.get(Integer.valueOf(i10)); if (num != null) { if (num.intValue() == 1) { m10.remove(Integer.valueOf(i10)); return; } else { m10.put(Integer.valueOf(i10), Integer.valueOf(num.intValue() - 1)); return; } } throw new NullPointerException("Tried to decrement empty size, size: " + i10 + ", this: " + this); } private void g() { h(this.f14280e); } private void h(int i10) { while (this.f14281f > i10) { Object f10 = this.f14276a.f(); m2.j.d(f10); t1.a i11 = i(f10); this.f14281f -= i11.b(f10) * i11.a(); f(i11.b(f10), f10.getClass()); if (Log.isLoggable(i11.getTag(), 2)) { Log.v(i11.getTag(), "evicted: " + i11.b(f10)); } } } private t1.a i(Object obj) { return j(obj.getClass()); } private t1.a j(Class cls) { t1.a aVar = (t1.a) this.f14279d.get(cls); if (aVar == null) { if (cls.equals(int[].class)) { aVar = new h(); } else { if (!cls.equals(byte[].class)) { throw new IllegalArgumentException("No array pool found for: " + cls.getSimpleName()); } aVar = new f(); } this.f14279d.put(cls, aVar); } return aVar; } private Object k(a aVar) { return this.f14276a.a(aVar); } private Object l(a aVar, Class cls) { t1.a j10 = j(cls); Object k10 = k(aVar); if (k10 != null) { this.f14281f -= j10.b(k10) * j10.a(); f(j10.b(k10), cls); } if (k10 != null) { return k10; } if (Log.isLoggable(j10.getTag(), 2)) { Log.v(j10.getTag(), "Allocated " + aVar.f14283b + " bytes"); } return j10.newArray(aVar.f14283b); } private NavigableMap m(Class cls) { NavigableMap navigableMap = (NavigableMap) this.f14278c.get(cls); if (navigableMap != null) { return navigableMap; } TreeMap treeMap = new TreeMap(); this.f14278c.put(cls, treeMap); return treeMap; } private boolean n() { int i10 = this.f14281f; return i10 == 0 || this.f14280e / i10 >= 2; } private boolean o(int i10) { return i10 <= this.f14280e / 2; } private boolean p(int i10, Integer num) { return num != null && (n() || num.intValue() <= i10 * 8); } @Override // t1.b public synchronized void a(int i10) { try { if (i10 >= 40) { b(); } else if (i10 >= 20 || i10 == 15) { h(this.f14280e / 2); } } catch (Throwable th) { throw th; } } @Override // t1.b public synchronized void b() { h(0); } @Override // t1.b public synchronized Object c(int i10, Class cls) { return l(this.f14277b.e(i10, cls), cls); } @Override // t1.b public synchronized void d(Object obj) { Class cls = obj.getClass(); t1.a j10 = j(cls); int b10 = j10.b(obj); int a10 = j10.a() * b10; if (o(a10)) { a e10 = this.f14277b.e(b10, cls); this.f14276a.d(e10, obj); NavigableMap m10 = m(cls); Integer num = (Integer) m10.get(Integer.valueOf(e10.f14283b)); Integer valueOf = Integer.valueOf(e10.f14283b); int i10 = 1; if (num != null) { i10 = 1 + num.intValue(); } m10.put(valueOf, Integer.valueOf(i10)); this.f14281f += a10; g(); } } @Override // t1.b public synchronized Object e(int i10, Class cls) { Integer num; num = (Integer) m(cls).ceilingKey(Integer.valueOf(i10)); return l(p(i10, num) ? this.f14277b.e(num.intValue(), cls) : this.f14277b.e(i10, cls), cls); } }