package s3;

import kotlin.jvm.internal.t;

/* loaded from: classes.dex */
public class g implements f {

    /* renamed from: a, reason: collision with root package name */
    private final Object[] f35410a;

    /* renamed from: b, reason: collision with root package name */
    private int f35411b;

    public g(int i10) {
        if (!(i10 > 0)) {
            throw new IllegalArgumentException("The max pool size must be > 0".toString());
        }
        this.f35410a = new Object[i10];
    }

    private final boolean c(Object obj) {
        int i10 = this.f35411b;
        for (int i11 = 0; i11 < i10; i11++) {
            if (this.f35410a[i11] == obj) {
                return true;
            }
        }
        return false;
    }

    @Override // s3.f
    public boolean a(Object instance) {
        t.g(instance, "instance");
        if (!(!c(instance))) {
            throw new IllegalStateException("Already in the pool!".toString());
        }
        int i10 = this.f35411b;
        Object[] objArr = this.f35410a;
        if (i10 >= objArr.length) {
            return false;
        }
        objArr[i10] = instance;
        this.f35411b = i10 + 1;
        return true;
    }

    @Override // s3.f
    public Object b() {
        int i10 = this.f35411b;
        if (i10 <= 0) {
            return null;
        }
        int i11 = i10 - 1;
        Object obj = this.f35410a[i11];
        t.e(obj, "null cannot be cast to non-null type T of androidx.core.util.Pools.SimplePool");
        this.f35410a[i11] = null;
        this.f35411b--;
        return obj;
    }
}
