package androidx.core.util; import androidx.annotation.IntRange; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.SourceDebugExtension; /* loaded from: classes.dex */ public final class Pools { public interface Pool { T acquire(); boolean release(T t); } private Pools() { } @SourceDebugExtension({"SMAP\nPools.kt\nKotlin\n*S Kotlin\n*F\n+ 1 Pools.kt\nandroidx/core/util/Pools$SimplePool\n+ 2 fake.kt\nkotlin/jvm/internal/FakeKt\n*L\n1#1,133:1\n1#2:134\n*E\n"}) public static class SimplePool implements Pool { private final Object[] pool; private int poolSize; public SimplePool(@IntRange(from = 1) int i) { if (i <= 0) { throw new IllegalArgumentException("The max pool size must be > 0".toString()); } this.pool = new Object[i]; } @Override // androidx.core.util.Pools.Pool public T acquire() { int i = this.poolSize; if (i <= 0) { return null; } int i2 = i - 1; T t = (T) this.pool[i2]; Intrinsics.checkNotNull(t, "null cannot be cast to non-null type T of androidx.core.util.Pools.SimplePool"); this.pool[i2] = null; this.poolSize--; return t; } @Override // androidx.core.util.Pools.Pool public boolean release(T instance) { Intrinsics.checkNotNullParameter(instance, "instance"); if (!(!isInPool(instance))) { throw new IllegalStateException("Already in the pool!".toString()); } int i = this.poolSize; Object[] objArr = this.pool; if (i >= objArr.length) { return false; } objArr[i] = instance; this.poolSize = i + 1; return true; } private final boolean isInPool(T t) { int i = this.poolSize; for (int i2 = 0; i2 < i; i2++) { if (this.pool[i2] == t) { return true; } } return false; } } public static class SynchronizedPool extends SimplePool { private final Object lock; public SynchronizedPool(int i) { super(i); this.lock = new Object(); } @Override // androidx.core.util.Pools.SimplePool, androidx.core.util.Pools.Pool public T acquire() { T t; synchronized (this.lock) { t = (T) super.acquire(); } return t; } @Override // androidx.core.util.Pools.SimplePool, androidx.core.util.Pools.Pool public boolean release(T instance) { boolean release; Intrinsics.checkNotNullParameter(instance, "instance"); synchronized (this.lock) { release = super.release(instance); } return release; } } }