package com.google.protobuf;

import com.google.protobuf.v1;
import java.util.Arrays;

/* loaded from: classes3.dex */
public final class p1 {

    /* renamed from: f, reason: collision with root package name */
    private static final p1 f15154f = new p1(0, new int[0], new Object[0], false);

    /* renamed from: a, reason: collision with root package name */
    private int f15155a;

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

    /* renamed from: c, reason: collision with root package name */
    private Object[] f15157c;

    /* renamed from: d, reason: collision with root package name */
    private int f15158d;

    /* renamed from: e, reason: collision with root package name */
    private boolean f15159e;

    private p1() {
        this(0, new int[8], new Object[8], true);
    }

    private void b(int i10) {
        int[] iArr = this.f15156b;
        if (i10 > iArr.length) {
            int i11 = this.f15155a;
            int i12 = i11 + (i11 / 2);
            if (i12 >= i10) {
                i10 = i12;
            }
            if (i10 < 8) {
                i10 = 8;
            }
            this.f15156b = Arrays.copyOf(iArr, i10);
            this.f15157c = Arrays.copyOf(this.f15157c, i10);
        }
    }

    public static p1 c() {
        return f15154f;
    }

    private static int f(int[] iArr, int i10) {
        int i11 = 17;
        for (int i12 = 0; i12 < i10; i12++) {
            i11 = (i11 * 31) + iArr[i12];
        }
        return i11;
    }

    private static int g(Object[] objArr, int i10) {
        int i11 = 17;
        for (int i12 = 0; i12 < i10; i12++) {
            i11 = (i11 * 31) + objArr[i12].hashCode();
        }
        return i11;
    }

    private p1 j(i iVar) {
        int F;
        do {
            F = iVar.F();
            if (F == 0) {
                break;
            }
        } while (i(F, iVar));
        return this;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static p1 n(p1 p1Var, p1 p1Var2) {
        int i10 = p1Var.f15155a + p1Var2.f15155a;
        int[] copyOf = Arrays.copyOf(p1Var.f15156b, i10);
        System.arraycopy(p1Var2.f15156b, 0, copyOf, p1Var.f15155a, p1Var2.f15155a);
        Object[] copyOf2 = Arrays.copyOf(p1Var.f15157c, i10);
        System.arraycopy(p1Var2.f15157c, 0, copyOf2, p1Var.f15155a, p1Var2.f15155a);
        return new p1(i10, copyOf, copyOf2, true);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static p1 o() {
        return new p1();
    }

    private static boolean p(Object[] objArr, Object[] objArr2, int i10) {
        for (int i11 = 0; i11 < i10; i11++) {
            if (!objArr[i11].equals(objArr2[i11])) {
                return false;
            }
        }
        return true;
    }

    private static boolean s(int[] iArr, int[] iArr2, int i10) {
        for (int i11 = 0; i11 < i10; i11++) {
            if (iArr[i11] != iArr2[i11]) {
                return false;
            }
        }
        return true;
    }

    private static void u(int i10, Object obj, v1 v1Var) {
        int a10 = u1.a(i10);
        int b10 = u1.b(i10);
        if (b10 == 0) {
            v1Var.n(a10, ((Long) obj).longValue());
            return;
        }
        if (b10 == 1) {
            v1Var.h(a10, ((Long) obj).longValue());
            return;
        }
        if (b10 == 2) {
            v1Var.N(a10, (h) obj);
            return;
        }
        if (b10 != 3) {
            if (b10 != 5) {
                throw new RuntimeException(a0.e());
            }
            v1Var.d(a10, ((Integer) obj).intValue());
        } else if (v1Var.i() == v1.a.ASCENDING) {
            v1Var.q(a10);
            ((p1) obj).v(v1Var);
            v1Var.B(a10);
        } else {
            v1Var.B(a10);
            ((p1) obj).v(v1Var);
            v1Var.q(a10);
        }
    }

    void a() {
        if (!this.f15159e) {
            throw new UnsupportedOperationException();
        }
    }

    public int d() {
        int V;
        int i10 = this.f15158d;
        if (i10 != -1) {
            return i10;
        }
        int i11 = 0;
        for (int i12 = 0; i12 < this.f15155a; i12++) {
            int i13 = this.f15156b[i12];
            int a10 = u1.a(i13);
            int b10 = u1.b(i13);
            if (b10 == 0) {
                V = k.V(a10, ((Long) this.f15157c[i12]).longValue());
            } else if (b10 == 1) {
                V = k.p(a10, ((Long) this.f15157c[i12]).longValue());
            } else if (b10 == 2) {
                V = k.h(a10, (h) this.f15157c[i12]);
            } else if (b10 == 3) {
                V = (k.S(a10) * 2) + ((p1) this.f15157c[i12]).d();
            } else {
                if (b10 != 5) {
                    throw new IllegalStateException(a0.e());
                }
                V = k.n(a10, ((Integer) this.f15157c[i12]).intValue());
            }
            i11 += V;
        }
        this.f15158d = i11;
        return i11;
    }

    public int e() {
        int i10 = this.f15158d;
        if (i10 != -1) {
            return i10;
        }
        int i11 = 0;
        for (int i12 = 0; i12 < this.f15155a; i12++) {
            i11 += k.H(u1.a(this.f15156b[i12]), (h) this.f15157c[i12]);
        }
        this.f15158d = i11;
        return i11;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || !(obj instanceof p1)) {
            return false;
        }
        p1 p1Var = (p1) obj;
        int i10 = this.f15155a;
        return i10 == p1Var.f15155a && s(this.f15156b, p1Var.f15156b, i10) && p(this.f15157c, p1Var.f15157c, this.f15155a);
    }

    public void h() {
        if (this.f15159e) {
            this.f15159e = false;
        }
    }

    public int hashCode() {
        int i10 = this.f15155a;
        return ((((527 + i10) * 31) + f(this.f15156b, i10)) * 31) + g(this.f15157c, this.f15155a);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean i(int i10, i iVar) {
        a();
        int a10 = u1.a(i10);
        int b10 = u1.b(i10);
        if (b10 == 0) {
            r(i10, Long.valueOf(iVar.x()));
            return true;
        }
        if (b10 == 1) {
            r(i10, Long.valueOf(iVar.u()));
            return true;
        }
        if (b10 == 2) {
            r(i10, iVar.q());
            return true;
        }
        if (b10 == 3) {
            p1 p1Var = new p1();
            p1Var.j(iVar);
            iVar.a(u1.c(a10, 4));
            r(i10, p1Var);
            return true;
        }
        if (b10 == 4) {
            return false;
        }
        if (b10 != 5) {
            throw a0.e();
        }
        r(i10, Integer.valueOf(iVar.t()));
        return true;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public p1 k(p1 p1Var) {
        if (p1Var.equals(c())) {
            return this;
        }
        a();
        int i10 = this.f15155a + p1Var.f15155a;
        b(i10);
        System.arraycopy(p1Var.f15156b, 0, this.f15156b, this.f15155a, p1Var.f15155a);
        System.arraycopy(p1Var.f15157c, 0, this.f15157c, this.f15155a, p1Var.f15155a);
        this.f15155a = i10;
        return this;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public p1 l(int i10, h hVar) {
        a();
        if (i10 == 0) {
            throw new IllegalArgumentException("Zero is not a valid field number.");
        }
        r(u1.c(i10, 2), hVar);
        return this;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public p1 m(int i10, int i11) {
        a();
        if (i10 == 0) {
            throw new IllegalArgumentException("Zero is not a valid field number.");
        }
        r(u1.c(i10, 0), Long.valueOf(i11));
        return this;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public final void q(StringBuilder sb2, int i10) {
        for (int i11 = 0; i11 < this.f15155a; i11++) {
            t0.d(sb2, i10, String.valueOf(u1.a(this.f15156b[i11])), this.f15157c[i11]);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void r(int i10, Object obj) {
        a();
        b(this.f15155a + 1);
        int[] iArr = this.f15156b;
        int i11 = this.f15155a;
        iArr[i11] = i10;
        this.f15157c[i11] = obj;
        this.f15155a = i11 + 1;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void t(v1 v1Var) {
        if (v1Var.i() == v1.a.DESCENDING) {
            for (int i10 = this.f15155a - 1; i10 >= 0; i10--) {
                v1Var.c(u1.a(this.f15156b[i10]), this.f15157c[i10]);
            }
            return;
        }
        for (int i11 = 0; i11 < this.f15155a; i11++) {
            v1Var.c(u1.a(this.f15156b[i11]), this.f15157c[i11]);
        }
    }

    public void v(v1 v1Var) {
        if (this.f15155a == 0) {
            return;
        }
        if (v1Var.i() == v1.a.ASCENDING) {
            for (int i10 = 0; i10 < this.f15155a; i10++) {
                u(this.f15156b[i10], this.f15157c[i10], v1Var);
            }
            return;
        }
        for (int i11 = this.f15155a - 1; i11 >= 0; i11--) {
            u(this.f15156b[i11], this.f15157c[i11], v1Var);
        }
    }

    private p1(int i10, int[] iArr, Object[] objArr, boolean z10) {
        this.f15158d = -1;
        this.f15155a = i10;
        this.f15156b = iArr;
        this.f15157c = objArr;
        this.f15159e = z10;
    }
}
