package androidx.recyclerview.widget;

import java.util.Arrays;

/* JADX INFO: loaded from: classes.dex */
public final class x implements o1 {

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

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

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

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

    public final void a(int i10, int i11) {
        if (i10 < 0) {
            throw new IllegalArgumentException("Layout positions must be non-negative");
        }
        if (i11 < 0) {
            throw new IllegalArgumentException("Pixel distance must be non-negative");
        }
        int i12 = this.f3952d;
        int i13 = i12 * 2;
        int[] iArr = this.f3951c;
        if (iArr == null) {
            int[] iArr2 = new int[4];
            this.f3951c = iArr2;
            Arrays.fill(iArr2, -1);
        } else if (i13 >= iArr.length) {
            int[] iArr3 = new int[i12 * 4];
            this.f3951c = iArr3;
            System.arraycopy(iArr, 0, iArr3, 0, iArr.length);
        }
        int[] iArr4 = this.f3951c;
        iArr4[i13] = i10;
        iArr4[i13 + 1] = i11;
        this.f3952d++;
    }

    public final void b(RecyclerView recyclerView, boolean z10) {
        this.f3952d = 0;
        int[] iArr = this.f3951c;
        if (iArr != null) {
            Arrays.fill(iArr, -1);
        }
        q1 q1Var = recyclerView.mLayout;
        if (recyclerView.mAdapter == null || q1Var == null || !q1Var.isItemPrefetchEnabled()) {
            return;
        }
        if (z10) {
            if (!recyclerView.mAdapterHelper.g()) {
                q1Var.collectInitialPrefetchPositions(recyclerView.mAdapter.getItemCount(), this);
            }
        } else if (!recyclerView.hasPendingAdapterUpdates()) {
            q1Var.collectAdjacentPrefetchPositions(this.f3949a, this.f3950b, recyclerView.mState, this);
        }
        int i10 = this.f3952d;
        if (i10 > q1Var.mPrefetchMaxCountObserved) {
            q1Var.mPrefetchMaxCountObserved = i10;
            q1Var.mPrefetchMaxObservedInInitialPrefetch = z10;
            recyclerView.mRecycler.n();
        }
    }
}
