package o; import java.io.IOException; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.NoSuchElementException; import o.QwV; import org.bouncycastle.crypto.tls.CipherSuite; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public final class RAv extends QwV { static final int[] c = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, CipherSuite.TLS_DHE_PSK_WITH_AES_128_CBC_SHA, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, Integer.MAX_VALUE}; private final int b; private final QwV d; final int e; private final int f; private final QwV j; /* synthetic */ RAv(QwV qwV, QwV qwV2, byte b) { this(qwV, qwV2); } private RAv(QwV qwV, QwV qwV2) { this.d = qwV; this.j = qwV2; int g = qwV.g(); this.b = g; this.f = g + qwV2.g(); this.e = Math.max(qwV.e(), qwV2.e()) + 1; } /* JADX INFO: Access modifiers changed from: package-private */ public static QwV a(QwV qwV, QwV qwV2) { if (qwV2.g() == 0) { return qwV; } if (qwV.g() == 0) { return qwV2; } int g = qwV.g() + qwV2.g(); if (g < 128) { return c(qwV, qwV2); } if (qwV instanceof RAv) { RAv rAv = (RAv) qwV; if (rAv.j.g() + qwV2.g() < 128) { return new RAv(rAv.d, c(rAv.j, qwV2)); } if (rAv.d.e() > rAv.j.e() && rAv.e > qwV2.e()) { return new RAv(rAv.d, new RAv(rAv.j, qwV2)); } } int max = Math.max(qwV.e(), qwV2.e()) + 1; int[] iArr = c; if (g >= (max >= iArr.length ? Integer.MAX_VALUE : iArr[max])) { return new RAv(qwV, qwV2); } byte b = 0; LWm lWm = new LWm(b); lWm.b(qwV); lWm.b(qwV2); QwV pop = lWm.a.pop(); while (!lWm.a.isEmpty()) { pop = new RAv(lWm.a.pop(), pop, b); } return pop; } private static QwV c(QwV qwV, QwV qwV2) { int g = qwV.g(); int g2 = qwV2.g(); byte[] bArr = new byte[g + g2]; qwV.d(bArr, 0, g); qwV2.d(bArr, g, g2); return new QwV.ojQ(bArr); } static int c(int i) { int[] iArr = c; if (i >= iArr.length) { return Integer.MAX_VALUE; } return iArr[i]; } @Override // o.QwV public final byte b(int i) { b(i, this.f); int i2 = this.b; if (i < i2) { return this.d.a(i); } return this.j.a(i - i2); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // o.QwV public final byte a(int i) { int i2 = this.b; if (i < i2) { return this.d.a(i); } return this.j.a(i - i2); } /* renamed from: o.RAv$1, reason: invalid class name */ /* loaded from: classes2.dex */ final class AnonymousClass1 extends QwV.LWm { private QwV.HBt b; private HBt c; private RAv d; AnonymousClass1(RAv rAv) { QwV.HBt hBt; this.d = rAv; HBt hBt2 = new HBt(rAv, (byte) 0); this.c = hBt2; if (hBt2.hasNext()) { HBt hBt3 = this.c; QwV.tOB tob = hBt3.e; if (tob == null) { throw new NoSuchElementException(); } hBt3.e = hBt3.e(); hBt = tob.iterator(); } else { hBt = null; } this.b = hBt; } @Override // o.QwV.HBt public final byte a() { QwV.HBt hBt; QwV.HBt hBt2 = this.b; if (hBt2 == null) { throw new NoSuchElementException(); } byte a = hBt2.a(); if (!this.b.hasNext()) { if (this.c.hasNext()) { HBt hBt3 = this.c; QwV.tOB tob = hBt3.e; if (tob == null) { throw new NoSuchElementException(); } hBt3.e = hBt3.e(); hBt = tob.iterator(); } else { hBt = null; } this.b = hBt; } return a; } @Override // java.util.Iterator public final boolean hasNext() { return this.b != null; } } @Override // o.QwV /* renamed from: a */ public final QwV.HBt iterator() { return new AnonymousClass1(this); } /* JADX INFO: Access modifiers changed from: protected */ @Override // o.QwV public final boolean b() { int i = this.f; int i2 = this.e; int[] iArr = c; return i >= (i2 >= iArr.length ? Integer.MAX_VALUE : iArr[i2]); } @Override // o.QwV public final QwV a(int i, int i2) { int a = a(i, i2, this.f); if (a == 0) { return QwV.a; } if (a == this.f) { return this; } int i3 = this.b; if (i2 <= i3) { return this.d.a(i, i2); } if (i >= i3) { return this.j.a(i - i3, i2 - i3); } QwV qwV = this.d; return new RAv(qwV.a(i, qwV.g()), this.j.a(0, i2 - this.b)); } /* JADX INFO: Access modifiers changed from: protected */ @Override // o.QwV public final void b(byte[] bArr, int i, int i2, int i3) { int i4 = this.b; if (i + i3 <= i4) { this.d.b(bArr, i, i2, i3); } else { if (i >= i4) { this.j.b(bArr, i - i4, i2, i3); return; } int i5 = i4 - i; this.d.b(bArr, i, i2, i5); this.j.b(bArr, 0, i2 + i5, i3 - i5); } } @Override // o.QwV public final ByteBuffer c() { return ByteBuffer.wrap(j()).asReadOnlyBuffer(); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // o.QwV public final void b(MZj mZj) throws IOException { this.d.b(mZj); this.j.b(mZj); } @Override // o.QwV protected final String a(Charset charset) { return new String(j(), charset); } @Override // o.QwV public final boolean d() { int e = this.d.e(0, 0, this.b); QwV qwV = this.j; return qwV.e(e, 0, qwV.g()) == 0; } /* JADX INFO: Access modifiers changed from: protected */ @Override // o.QwV public final int e(int i, int i2, int i3) { int i4 = this.b; if (i2 + i3 <= i4) { return this.d.e(i, i2, i3); } if (i2 >= i4) { return this.j.e(i, i2 - i4, i3); } int i5 = i4 - i2; return this.j.e(this.d.e(i, i2, i5), 0, i3 - i5); } public final boolean equals(Object obj) { boolean c2; if (obj == this) { return true; } byte b = 0; if (!(obj instanceof QwV)) { return false; } QwV qwV = (QwV) obj; if (this.f != qwV.g()) { return false; } if (this.f == 0) { return true; } int h = h(); int h2 = qwV.h(); if (h != 0 && h2 != 0 && h != h2) { return false; } HBt hBt = new HBt(this, b); QwV.tOB next = hBt.next(); HBt hBt2 = new HBt(qwV, b); QwV.tOB next2 = hBt2.next(); int i = 0; int i2 = 0; int i3 = 0; while (true) { int g = next.g() - i; int g2 = next2.g() - i2; int min = Math.min(g, g2); if (i == 0) { c2 = next.c(next2, i2, min); } else { c2 = next2.c(next, i, min); } if (!c2) { return false; } i3 += min; int i4 = this.f; if (i3 >= i4) { if (i3 == i4) { return true; } throw new IllegalStateException(); } if (min == g) { i = 0; next = hBt.next(); } else { i += min; next = next; } if (min == g2) { next2 = hBt2.next(); i2 = 0; } else { i2 += min; } } } /* JADX INFO: Access modifiers changed from: protected */ @Override // o.QwV public final int d(int i, int i2, int i3) { int i4 = this.b; if (i2 + i3 <= i4) { return this.d.d(i, i2, i3); } if (i2 >= i4) { return this.j.d(i, i2 - i4, i3); } int i5 = i4 - i2; return this.j.d(this.d.d(i, i2, i5), 0, i3 - i5); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static class LWm { final ArrayDeque a; private LWm() { this.a = new ArrayDeque<>(); } /* synthetic */ LWm(byte b) { this(); } final void b(QwV qwV) { byte b; while (!qwV.b()) { if (qwV instanceof RAv) { RAv rAv = (RAv) qwV; b(rAv.d); qwV = rAv.j; } else { StringBuilder sb = new StringBuilder("Has a new type of ByteString been created? Found "); sb.append(qwV.getClass()); throw new IllegalArgumentException(sb.toString()); } } int binarySearch = Arrays.binarySearch(RAv.c, qwV.g()); if (binarySearch < 0) { binarySearch = (-(binarySearch + 1)) - 1; } int c = RAv.c(binarySearch + 1); if (this.a.isEmpty() || this.a.peek().g() >= c) { this.a.push(qwV); return; } int c2 = RAv.c(binarySearch); QwV pop = this.a.pop(); while (true) { b = 0; if (this.a.isEmpty() || this.a.peek().g() >= c2) { break; } else { pop = new RAv(this.a.pop(), pop, b); } } RAv rAv2 = new RAv(pop, qwV, b); while (!this.a.isEmpty()) { int binarySearch2 = Arrays.binarySearch(RAv.c, rAv2.g()); if (binarySearch2 < 0) { binarySearch2 = (-(binarySearch2 + 1)) - 1; } if (this.a.peek().g() >= RAv.c(binarySearch2 + 1)) { break; } else { rAv2 = new RAv(this.a.pop(), rAv2, b); } } this.a.push(rAv2); } } /* loaded from: classes2.dex */ static final class HBt implements Iterator { private final ArrayDeque c; QwV.tOB e; /* synthetic */ HBt(QwV qwV, byte b) { this(qwV); } @Override // java.util.Iterator public final /* synthetic */ QwV.tOB next() { QwV.tOB tob = this.e; if (tob == null) { throw new NoSuchElementException(); } this.e = e(); return tob; } private HBt(QwV qwV) { if (qwV instanceof RAv) { RAv rAv = (RAv) qwV; ArrayDeque arrayDeque = new ArrayDeque<>(rAv.e); this.c = arrayDeque; arrayDeque.push(rAv); this.e = e(rAv.d); return; } this.c = null; this.e = (QwV.tOB) qwV; } private QwV.tOB e(QwV qwV) { while (qwV instanceof RAv) { RAv rAv = (RAv) qwV; this.c.push(rAv); qwV = rAv.d; } return (QwV.tOB) qwV; } final QwV.tOB e() { QwV.tOB e; do { ArrayDeque arrayDeque = this.c; if (arrayDeque == null || arrayDeque.isEmpty()) { return null; } e = e(this.c.pop().j); } while (e.g() == 0); return e; } @Override // java.util.Iterator public final void remove() { throw new UnsupportedOperationException(); } @Override // java.util.Iterator public final boolean hasNext() { return this.e != null; } } final Object writeReplace() { return new QwV.ojQ(j()); } private void readObject(ObjectInputStream objectInputStream) throws IOException { throw new InvalidObjectException("RopeByteStream instances are not to be serialized directly"); } @Override // o.QwV, java.lang.Iterable public final /* synthetic */ Iterator iterator() { return new AnonymousClass1(this); } @Override // o.QwV public final cKE f() { ArrayList arrayList = new ArrayList(); HBt hBt = new HBt(this, (byte) 0); while (hBt.hasNext()) { QwV.tOB tob = hBt.e; if (tob == null) { throw new NoSuchElementException(); } hBt.e = hBt.e(); arrayList.add(tob.c()); } return cKE.a(arrayList); } @Override // o.QwV public final int g() { return this.f; } /* JADX INFO: Access modifiers changed from: protected */ @Override // o.QwV public final int e() { return this.e; } }