104 lines
3.2 KiB
Java
104 lines
3.2 KiB
Java
package com.bumptech.glide.util.pool;
|
|
|
|
import android.util.Log;
|
|
import androidx.core.util.Pools$Pool;
|
|
import androidx.core.util.Pools$SimplePool;
|
|
import androidx.core.util.Pools$SynchronizedPool;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class FactoryPools {
|
|
private static final Resetter<Object> a = new Resetter<Object>() { // from class: com.bumptech.glide.util.pool.FactoryPools.1
|
|
@Override // com.bumptech.glide.util.pool.FactoryPools.Resetter
|
|
public void a(Object obj) {
|
|
}
|
|
};
|
|
|
|
public interface Factory<T> {
|
|
T a();
|
|
}
|
|
|
|
public interface Poolable {
|
|
StateVerifier c();
|
|
}
|
|
|
|
public interface Resetter<T> {
|
|
void a(T t);
|
|
}
|
|
|
|
public static <T extends Poolable> Pools$Pool<T> a(int i, Factory<T> factory) {
|
|
return a(new Pools$SimplePool(i), factory);
|
|
}
|
|
|
|
public static <T extends Poolable> Pools$Pool<T> b(int i, Factory<T> factory) {
|
|
return a(new Pools$SynchronizedPool(i), factory);
|
|
}
|
|
|
|
public static <T> Pools$Pool<List<T>> a(int i) {
|
|
return a(new Pools$SynchronizedPool(i), new Factory<List<T>>() { // from class: com.bumptech.glide.util.pool.FactoryPools.2
|
|
@Override // com.bumptech.glide.util.pool.FactoryPools.Factory
|
|
public List<T> a() {
|
|
return new ArrayList();
|
|
}
|
|
}, new Resetter<List<T>>() { // from class: com.bumptech.glide.util.pool.FactoryPools.3
|
|
@Override // com.bumptech.glide.util.pool.FactoryPools.Resetter
|
|
public void a(List<T> list) {
|
|
list.clear();
|
|
}
|
|
});
|
|
}
|
|
|
|
public static <T> Pools$Pool<List<T>> b() {
|
|
return a(20);
|
|
}
|
|
|
|
private static <T extends Poolable> Pools$Pool<T> a(Pools$Pool<T> pools$Pool, Factory<T> factory) {
|
|
return a(pools$Pool, factory, a());
|
|
}
|
|
|
|
private static <T> Pools$Pool<T> a(Pools$Pool<T> pools$Pool, Factory<T> factory, Resetter<T> resetter) {
|
|
return new FactoryPool(pools$Pool, factory, resetter);
|
|
}
|
|
|
|
private static <T> Resetter<T> a() {
|
|
return (Resetter<T>) a;
|
|
}
|
|
|
|
private static final class FactoryPool<T> implements Pools$Pool<T> {
|
|
private final Factory<T> a;
|
|
private final Resetter<T> b;
|
|
private final Pools$Pool<T> c;
|
|
|
|
FactoryPool(Pools$Pool<T> pools$Pool, Factory<T> factory, Resetter<T> resetter) {
|
|
this.c = pools$Pool;
|
|
this.a = factory;
|
|
this.b = resetter;
|
|
}
|
|
|
|
@Override // androidx.core.util.Pools$Pool
|
|
public T a() {
|
|
T a = this.c.a();
|
|
if (a == null) {
|
|
a = this.a.a();
|
|
if (Log.isLoggable("FactoryPools", 2)) {
|
|
Log.v("FactoryPools", "Created new " + a.getClass());
|
|
}
|
|
}
|
|
if (a instanceof Poolable) {
|
|
a.c().a(false);
|
|
}
|
|
return (T) a;
|
|
}
|
|
|
|
@Override // androidx.core.util.Pools$Pool
|
|
public boolean a(T t) {
|
|
if (t instanceof Poolable) {
|
|
((Poolable) t).c().a(true);
|
|
}
|
|
this.b.a(t);
|
|
return this.c.a(t);
|
|
}
|
|
}
|
|
}
|