package ඓ.ῲ.K.ᕣ.ᨨ.ゎ;

import android.util.Log;
import java.util.HashMap;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
import ඓ.K.K.K.C1293;
import ῲ.ᨨ.㳳.C1841;

/* renamed from: ඓ.ῲ.K.ᕣ.ᨨ.ゎ.ᨨ  reason: contains not printable characters */
/* compiled from: LruArrayPool */
public final class C0964 implements AbstractC0967 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public final Map<Class<?>, NavigableMap<Integer, Integer>> f4330 = new HashMap();

    /* renamed from: ඓ  reason: contains not printable characters */
    public final int f4331;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final C0965 f4332 = new C0965();

    /* renamed from: K  reason: contains not printable characters */
    public final C0968<C0966, Object> f4333 = new C0968<>();

    /* renamed from: 㴹  reason: contains not printable characters */
    public int f4334;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final Map<Class<?>, AbstractC0970<?>> f4335 = new HashMap();

    /* renamed from: ඓ.ῲ.K.ᕣ.ᨨ.ゎ.ᨨ$K  reason: contains not printable characters */
    /* compiled from: LruArrayPool */
    public static final class C0966 implements AbstractC0971 {

        /* renamed from: ʬ  reason: contains not printable characters */
        public Class<?> f4336;

        /* renamed from: ῲ  reason: contains not printable characters */
        public int f4337;

        /* renamed from: K  reason: contains not printable characters */
        public final C0965 f4338;

        public C0966(C0965 r1) {
            this.f4338 = r1;
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof C0966)) {
                return false;
            }
            C0966 k = (C0966) obj;
            if (this.f4337 == k.f4337 && this.f4336 == k.f4336) {
                return true;
            }
            return false;
        }

        public int hashCode() {
            int i = this.f4337 * 31;
            Class<?> cls = this.f4336;
            return i + (cls != null ? cls.hashCode() : 0);
        }

        public String toString() {
            StringBuilder r0 = C1293.m3416("Key{size=");
            r0.append(this.f4337);
            r0.append("array=");
            r0.append(this.f4336);
            r0.append('}');
            return r0.toString();
        }

        @Override // ඓ.ῲ.K.ᕣ.ᨨ.ゎ.AbstractC0971
        /* renamed from: K  reason: contains not printable characters */
        public void m2746() {
            this.f4338.m2722(this);
        }
    }

    public C0964(int i) {
        this.f4331 = i;
    }

    /* JADX DEBUG: Multi-variable search result rejected for r3v0, resolved type: java.lang.Class<T> */
    /* JADX WARN: Multi-variable type inference failed */
    /* renamed from: ʬ  reason: contains not printable characters */
    public synchronized <T> T m2734(int i, Class<T> cls) {
        C0966 k;
        k = (C0966) this.f4332.m2720();
        k.f4337 = i;
        k.f4336 = cls;
        return (T) m2738(k, cls);
    }

    /* JADX DEBUG: Multi-variable search result rejected for r7v0, resolved type: java.lang.Class<T> */
    /* JADX WARN: Multi-variable type inference failed */
    /* renamed from: ῲ  reason: contains not printable characters */
    public synchronized <T> T m2735(int i, Class<T> cls) {
        C0966 k;
        boolean z;
        Integer ceilingKey = m2736((Class<?>) cls).ceilingKey(Integer.valueOf(i));
        boolean z2 = false;
        if (ceilingKey != null) {
            int i2 = this.f4334;
            if (i2 != 0) {
                if (this.f4331 / i2 < 2) {
                    z = false;
                    if (z || ceilingKey.intValue() <= i * 8) {
                        z2 = true;
                    }
                }
            }
            z = true;
            z2 = true;
        }
        if (z2) {
            k = this.f4332.m2744(ceilingKey.intValue(), cls);
        } else {
            C0966 k2 = (C0966) this.f4332.m2720();
            k2.f4337 = i;
            k2.f4336 = cls;
            k = k2;
        }
        return (T) m2738(k, cls);
    }

    /* renamed from: K  reason: contains not printable characters */
    public synchronized <T> void m2743(T t) {
        Class<?> cls = t.getClass();
        AbstractC0970<T> r1 = m2739((Class) cls);
        int r2 = r1.m2753(t);
        int r12 = r1.m2752() * r2;
        int i = 1;
        if (r12 <= this.f4331 / 2) {
            C0966 r22 = this.f4332.m2744(r2, cls);
            this.f4333.m2750(r22, t);
            NavigableMap<Integer, Integer> r6 = m2736(cls);
            Integer num = (Integer) r6.get(Integer.valueOf(r22.f4337));
            Integer valueOf = Integer.valueOf(r22.f4337);
            if (num != null) {
                i = 1 + num.intValue();
            }
            r6.put(valueOf, Integer.valueOf(i));
            this.f4334 += r12;
            m2741(this.f4331);
        }
    }

    /* renamed from: ඓ.ῲ.K.ᕣ.ᨨ.ゎ.ᨨ$ῲ  reason: contains not printable characters */
    /* compiled from: LruArrayPool */
    public static final class C0965 extends AbstractC0961<C0966> {
        /* renamed from: K  reason: contains not printable characters */
        public C0966 m2744(int i, Class<?> cls) {
            C0966 k = (C0966) m2720();
            k.f4337 = i;
            k.f4336 = cls;
            return k;
        }

        /* Return type fixed from 'ඓ.ῲ.K.ᕣ.ᨨ.ゎ.㑃' to match base method */
        @Override // ඓ.ῲ.K.ᕣ.ᨨ.ゎ.AbstractC0961
        /* renamed from: K  reason: contains not printable characters */
        public C0966 m2745() {
            return new C0966(this);
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public synchronized void m2737(int i) {
        if (i >= 40) {
            try {
                m2740();
            } catch (Throwable th) {
                throw th;
            }
        } else if (i >= 20 || i == 15) {
            m2741(this.f4331 / 2);
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public final NavigableMap<Integer, Integer> m2736(Class<?> cls) {
        NavigableMap<Integer, Integer> navigableMap = this.f4330.get(cls);
        if (navigableMap != null) {
            return navigableMap;
        }
        TreeMap treeMap = new TreeMap();
        this.f4330.put(cls, treeMap);
        return treeMap;
    }

    /* renamed from: K  reason: contains not printable characters */
    public final <T> T m2738(C0966 k, Class<T> cls) {
        AbstractC0970<T> r0 = m2739((Class) cls);
        T t = (T) this.f4333.m2749(k);
        if (t != null) {
            this.f4334 -= r0.m2752() * r0.m2753(t);
            m2742(r0.m2753(t), (Class<?>) cls);
        }
        if (t != null) {
            return t;
        }
        if (Log.isLoggable(r0.getTag(), 2)) {
            String tag = r0.getTag();
            StringBuilder r1 = C1293.m3416("Allocated ");
            r1.append(k.f4337);
            r1.append(" bytes");
            Log.v(tag, r1.toString());
        }
        return r0.newArray(k.f4337);
    }

    /* renamed from: K  reason: contains not printable characters */
    public synchronized void m2740() {
        m2741(0);
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m2741(int i) {
        while (this.f4334 > i) {
            Object r0 = this.f4333.m2748();
            C1841.m4783(r0, "Argument must not be null");
            AbstractC0970 r1 = m2739((Class) r0.getClass());
            this.f4334 -= r1.m2752() * r1.m2753(r0);
            m2742(r1.m2753(r0), r0.getClass());
            if (Log.isLoggable(r1.getTag(), 2)) {
                String tag = r1.getTag();
                StringBuilder r3 = C1293.m3416("evicted: ");
                r3.append(r1.m2753(r0));
                Log.v(tag, r3.toString());
            }
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m2742(int i, Class<?> cls) {
        NavigableMap<Integer, Integer> r5 = m2736(cls);
        Integer num = (Integer) r5.get(Integer.valueOf(i));
        if (num == null) {
            throw new NullPointerException("Tried to decrement empty size, size: " + i + ", this: " + this);
        } else if (num.intValue() == 1) {
            r5.remove(Integer.valueOf(i));
        } else {
            r5.put(Integer.valueOf(i), Integer.valueOf(num.intValue() - 1));
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final <T> AbstractC0970<T> m2739(Class<T> cls) {
        C0975 r0 = (AbstractC0970<T>) this.f4335.get(cls);
        if (r0 == null) {
            if (cls.equals(int[].class)) {
                r0 = new C0977();
            } else if (cls.equals(byte[].class)) {
                r0 = new C0975();
            } else {
                StringBuilder r1 = C1293.m3416("No array pool found for: ");
                r1.append(cls.getSimpleName());
                throw new IllegalArgumentException(r1.toString());
            }
            this.f4335.put(cls, r0);
        }
        return r0;
    }
}
