package u;

/* JADX INFO: loaded from: classes.dex */
public class h implements p0.e {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f33146a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Object[] f33147b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f33148c;

    public h(int i10, int i11) {
        this.f33146a = i11;
        if (i11 != 1) {
            if (i10 <= 0) {
                throw new IllegalArgumentException("The max pool size must be > 0");
            }
            this.f33147b = new Object[i10];
        } else {
            if (i10 <= 0) {
                throw new IllegalArgumentException("The max pool size must be > 0".toString());
            }
            this.f33147b = new Object[i10];
        }
    }

    @Override // p0.e
    public boolean a(Object obj) {
        boolean z10;
        int i10 = this.f33146a;
        Object[] objArr = this.f33147b;
        switch (i10) {
            case 0:
                int i11 = this.f33148c;
                if (i11 >= objArr.length) {
                    return false;
                }
                objArr[i11] = obj;
                this.f33148c = i11 + 1;
                return true;
            default:
                nb.g.i(obj, "instance");
                int i12 = this.f33148c;
                int i13 = 0;
                while (true) {
                    if (i13 >= i12) {
                        z10 = false;
                    } else if (objArr[i13] == obj) {
                        z10 = true;
                    } else {
                        i13++;
                    }
                }
                if (!(!z10)) {
                    throw new IllegalStateException("Already in the pool!".toString());
                }
                int i14 = this.f33148c;
                if (i14 >= objArr.length) {
                    return false;
                }
                objArr[i14] = obj;
                this.f33148c = i14 + 1;
                return true;
        }
    }

    @Override // p0.e
    public Object acquire() {
        int i10 = this.f33146a;
        Object[] objArr = this.f33147b;
        switch (i10) {
            case 0:
                int i11 = this.f33148c;
                if (i11 <= 0) {
                    return null;
                }
                int i12 = i11 - 1;
                Object obj = objArr[i12];
                objArr[i12] = null;
                this.f33148c = i12;
                return obj;
            default:
                int i13 = this.f33148c;
                if (i13 <= 0) {
                    return null;
                }
                int i14 = i13 - 1;
                Object obj2 = objArr[i14];
                nb.g.g(obj2, "null cannot be cast to non-null type T of androidx.core.util.Pools.SimplePool");
                objArr[i14] = null;
                this.f33148c--;
                return obj2;
        }
    }
}
