discord-jadx/app/src/main/java/j0/l/a/x0.java

713 lines
25 KiB
Java

package j0.l.a;
import j0.l.e.h;
import j0.l.e.j;
import j0.l.e.m.g;
import j0.l.e.n.n;
import j0.l.e.n.y;
import java.util.ArrayList;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicLong;
import rx.Observable;
import rx.Producer;
import rx.Subscriber;
import rx.exceptions.CompositeException;
import rx.exceptions.MissingBackpressureException;
import rx.exceptions.OnErrorThrowable;
import rx.subscriptions.CompositeSubscription;
/* compiled from: OperatorMerge */
public final class x0<T> implements Observable.b<T, Observable<? extends T>> {
public final boolean i;
/* compiled from: OperatorMerge */
public static final class a {
public static final x0<Object> a = new x0<>(true, Integer.MAX_VALUE);
}
/* compiled from: OperatorMerge */
public static final class b {
public static final x0<Object> a = new x0<>(false, Integer.MAX_VALUE);
}
/* compiled from: OperatorMerge */
public static final class c<T> extends Subscriber<T> {
public static final int i = (h.i / 4);
public final e<T> j;
public final long k;
public volatile boolean l;
public volatile h m;
public int n;
public c(e<T> eVar, long j) {
this.j = eVar;
this.k = j;
}
public void a(long j) {
int i2 = this.n - ((int) j);
if (i2 > i) {
this.n = i2;
return;
}
int i3 = h.i;
this.n = i3;
int i4 = i3 - i2;
if (i4 > 0) {
request((long) i4);
}
}
@Override // j0.g
public void onCompleted() {
this.l = true;
this.j.b();
}
@Override // j0.g
public void onError(Throwable th) {
this.j.d().offer(th);
this.l = true;
this.j.b();
}
@Override // j0.g
public void onNext(T t) {
boolean z2;
Throwable th;
e<T> eVar = this.j;
long j = eVar.m.get();
boolean z3 = true;
if (j != 0) {
synchronized (eVar) {
j = eVar.m.get();
if (eVar.r || j == 0) {
z2 = false;
} else {
eVar.r = true;
z2 = true;
}
}
} else {
z2 = false;
}
if (z2) {
h hVar = this.m;
if (hVar != null) {
Queue<Object> queue = hVar.j;
if (!(queue == null || queue.isEmpty())) {
eVar.f(this, t);
eVar.c();
return;
}
}
try {
eVar.j.onNext(t);
} catch (Throwable th2) {
th = th2;
}
if (j != Long.MAX_VALUE) {
eVar.m.a(1);
}
a(1);
synchronized (eVar) {
if (!eVar.f2837s) {
eVar.r = false;
return;
}
eVar.f2837s = false;
eVar.c();
return;
}
}
eVar.f(this, t);
eVar.b();
return;
if (!z3) {
synchronized (eVar) {
eVar.r = false;
}
}
throw th;
}
@Override // rx.Subscriber
public void onStart() {
int i2 = h.i;
this.n = i2;
request((long) i2);
}
}
/* compiled from: OperatorMerge */
public static final class d<T> extends AtomicLong implements Producer {
private static final long serialVersionUID = -1214379189873595503L;
public final e<T> subscriber;
public d(e<T> eVar) {
this.subscriber = eVar;
}
public long a(int i) {
return addAndGet((long) (-i));
}
@Override // rx.Producer
public void j(long j) {
int i = (j > 0 ? 1 : (j == 0 ? 0 : -1));
if (i > 0) {
if (get() != Long.MAX_VALUE) {
c.q.a.k.a.p(this, j);
this.subscriber.b();
}
} else if (i < 0) {
throw new IllegalArgumentException("n >= 0 required");
}
}
}
/* compiled from: OperatorMerge */
public static final class e<T> extends Subscriber<Observable<? extends T>> {
public static final c<?>[] i = new c[0];
public final Subscriber<? super T> j;
public final boolean k;
public final int l;
public d<T> m;
public volatile Queue<Object> n;
public volatile CompositeSubscription o;
public volatile ConcurrentLinkedQueue<Throwable> p;
public volatile boolean q;
public boolean r;
/* renamed from: s reason: collision with root package name */
public boolean f2837s;
public final Object t = new Object();
public volatile c<?>[] u = i;
public long v;
public long w;
/* renamed from: x reason: collision with root package name */
public int f2838x;
/* renamed from: y reason: collision with root package name */
public final int f2839y;
/* renamed from: z reason: collision with root package name */
public int f2840z;
public e(Subscriber<? super T> subscriber, boolean z2, int i2) {
this.j = subscriber;
this.k = z2;
this.l = i2;
if (i2 == Integer.MAX_VALUE) {
this.f2839y = Integer.MAX_VALUE;
request(Long.MAX_VALUE);
return;
}
this.f2839y = Math.max(1, i2 >> 1);
request((long) i2);
}
public boolean a() {
if (this.j.isUnsubscribed()) {
return true;
}
ConcurrentLinkedQueue<Throwable> concurrentLinkedQueue = this.p;
if (this.k || concurrentLinkedQueue == null || concurrentLinkedQueue.isEmpty()) {
return false;
}
try {
h();
return true;
} finally {
unsubscribe();
}
}
public void b() {
synchronized (this) {
if (this.r) {
this.f2837s = true;
return;
}
this.r = true;
c();
}
}
/* JADX WARNING: Code restructure failed: missing block: B:121:0x0167, code lost:
if ((r4 == null || r4.isEmpty()) != false) goto L_0x0169;
*/
/* JADX WARNING: Code restructure failed: missing block: B:157:0x01b4, code lost:
r0 = th;
*/
/* JADX WARNING: Removed duplicated region for block: B:162:0x01bc */
public void c() {
boolean z2;
Throwable th;
Subscriber<? super T> subscriber;
long j;
int i2;
Subscriber<? super T> subscriber2;
boolean z3;
Throwable th2;
int i3;
long j2;
try {
subscriber = this.j;
return;
} catch (Throwable th3) {
th = th3;
z2 = false;
if (!z2) {
}
throw th;
}
while (!a()) {
Queue<Object> queue = this.n;
long j3 = this.m.get();
boolean z4 = j3 == Long.MAX_VALUE;
if (queue != null) {
int i4 = 0;
while (true) {
j = j3;
int i5 = 0;
i2 = i4;
Object obj = null;
while (true) {
if (j <= 0) {
break;
}
Object poll = queue.poll();
if (!a()) {
if (poll == null) {
obj = poll;
break;
}
try {
subscriber.onNext((Object) e.b(poll));
} catch (Throwable th4) {
th = th4;
z2 = true;
if (!z2) {
synchronized (this) {
this.r = false;
}
}
throw th;
}
i2++;
i5++;
j--;
obj = poll;
} else {
return;
}
}
if (i5 > 0) {
j = z4 ? Long.MAX_VALUE : this.m.a(i5);
}
if (j == 0 || obj == null) {
break;
}
i4 = i2;
j3 = j;
}
} else {
j = j3;
i2 = 0;
}
boolean z5 = this.q;
Queue<Object> queue2 = this.n;
c<?>[] cVarArr = this.u;
int length = cVarArr.length;
if (!z5 || ((queue2 != null && !queue2.isEmpty()) || length != 0)) {
if (length > 0) {
long j4 = this.w;
int i6 = this.f2838x;
if (length <= i6 || cVarArr[i6].k != j4) {
if (length <= i6) {
i6 = 0;
}
for (int i7 = 0; i7 < length && cVarArr[i6].k != j4; i7++) {
i6++;
if (i6 == length) {
i6 = 0;
}
}
this.f2838x = i6;
this.w = cVarArr[i6].k;
}
int i8 = 0;
z3 = false;
while (true) {
if (i8 >= length) {
subscriber2 = subscriber;
break;
} else if (!a()) {
c<?> cVar = cVarArr[i6];
Object obj2 = null;
while (true) {
int i9 = 0;
while (j > 0) {
if (!a()) {
h hVar = cVar.m;
if (hVar == null || (obj2 = hVar.c()) == null) {
break;
}
try {
subscriber.onNext((Object) e.b(obj2));
j--;
i9++;
} catch (Throwable th5) {
unsubscribe();
throw th5;
}
} else {
return;
}
}
if (i9 > 0) {
if (!z4) {
j2 = this.m.a(i9);
subscriber2 = subscriber;
} else {
subscriber2 = subscriber;
j2 = Long.MAX_VALUE;
}
cVar.a((long) i9);
j = j2;
} else {
subscriber2 = subscriber;
}
i3 = (j > 0 ? 1 : (j == 0 ? 0 : -1));
if (i3 == 0 || obj2 == null) {
break;
}
subscriber = subscriber2;
}
boolean z6 = cVar.l;
h hVar2 = cVar.m;
if (z6) {
if (hVar2 != null) {
Queue<Object> queue3 = hVar2.j;
}
g(cVar);
if (!a()) {
i2++;
z3 = true;
} else {
return;
}
}
if (i3 == 0) {
break;
}
i6++;
if (i6 == length) {
i6 = 0;
}
i8++;
subscriber = subscriber2;
} else {
return;
}
}
this.f2838x = i6;
this.w = cVarArr[i6].k;
} else {
subscriber2 = subscriber;
z3 = false;
}
if (i2 > 0) {
request((long) i2);
}
if (!z3) {
synchronized (this) {
try {
if (!this.f2837s) {
try {
this.r = false;
return;
} catch (Throwable th6) {
th2 = th6;
z2 = true;
while (true) {
try {
break;
} catch (Throwable th7) {
th2 = th7;
}
}
throw th2;
}
} else {
this.f2837s = false;
}
} catch (Throwable th8) {
th2 = th8;
z2 = false;
while (true) {
break;
}
throw th2;
}
}
}
subscriber = subscriber2;
} else {
ConcurrentLinkedQueue<Throwable> concurrentLinkedQueue = this.p;
if (concurrentLinkedQueue == null || concurrentLinkedQueue.isEmpty()) {
subscriber.onCompleted();
return;
} else {
h();
return;
}
}
}
}
public Queue<Throwable> d() {
ConcurrentLinkedQueue<Throwable> concurrentLinkedQueue = this.p;
if (concurrentLinkedQueue == null) {
synchronized (this) {
concurrentLinkedQueue = this.p;
if (concurrentLinkedQueue == null) {
concurrentLinkedQueue = new ConcurrentLinkedQueue<>();
this.p = concurrentLinkedQueue;
}
}
}
return concurrentLinkedQueue;
}
public void e(T t) {
Queue<Object> queue = this.n;
if (queue == null) {
int i2 = this.l;
if (i2 == Integer.MAX_VALUE) {
queue = new g<>(h.i);
} else {
queue = ((i2 + -1) & i2) == 0 ? y.b() ? new n<>(i2) : new j0.l.e.m.c<>(i2) : new j0.l.e.m.d<>(i2);
}
this.n = queue;
}
if (!queue.offer(t == null ? e.b : t)) {
unsubscribe();
d().offer(OnErrorThrowable.a(new MissingBackpressureException(), t));
this.q = true;
b();
}
}
public void f(c<T> cVar, T t) {
h hVar = cVar.m;
if (hVar == null) {
hVar = y.b() ? new h(false, h.i) : new h();
cVar.add(hVar);
cVar.m = hVar;
}
if (t == null) {
try {
t = (T) e.b;
} catch (MissingBackpressureException e) {
cVar.unsubscribe();
cVar.onError(e);
return;
} catch (IllegalStateException e2) {
if (!cVar.isUnsubscribed()) {
cVar.unsubscribe();
cVar.onError(e2);
return;
}
return;
}
}
hVar.a(t);
}
public void g(c<T> cVar) {
h hVar = cVar.m;
if (hVar != null) {
synchronized (hVar) {
}
}
this.o.c(cVar);
synchronized (this.t) {
c<?>[] cVarArr = this.u;
int length = cVarArr.length;
int i2 = 0;
while (true) {
if (i2 >= length) {
i2 = -1;
break;
} else if (cVar.equals(cVarArr[i2])) {
break;
} else {
i2++;
}
}
if (i2 >= 0) {
if (length == 1) {
this.u = i;
return;
}
c<?>[] cVarArr2 = new c[(length - 1)];
System.arraycopy(cVarArr, 0, cVarArr2, 0, i2);
System.arraycopy(cVarArr, i2 + 1, cVarArr2, i2, (length - i2) - 1);
this.u = cVarArr2;
}
}
}
public final void h() {
ArrayList arrayList = new ArrayList(this.p);
if (arrayList.size() == 1) {
this.j.onError((Throwable) arrayList.get(0));
} else {
this.j.onError(new CompositeException(arrayList));
}
}
@Override // j0.g
public void onCompleted() {
this.q = true;
b();
}
@Override // j0.g
public void onError(Throwable th) {
d().offer(th);
this.q = true;
b();
}
@Override // j0.g
public void onNext(Object obj) {
boolean z2;
boolean z3;
Throwable th;
Observable<Object> observable = (Observable) obj;
if (observable != null) {
z2 = true;
if (observable == c.j) {
int i2 = this.f2840z + 1;
if (i2 == this.f2839y) {
this.f2840z = 0;
request((long) i2);
return;
}
this.f2840z = i2;
return;
} else if (observable instanceof j) {
T t = ((j) observable).k;
long j = this.m.get();
if (j != 0) {
synchronized (this) {
j = this.m.get();
if (this.r || j == 0) {
z3 = false;
} else {
this.r = true;
z3 = true;
}
}
} else {
z3 = false;
}
if (z3) {
Queue<Object> queue = this.n;
if (queue == null || queue.isEmpty()) {
try {
this.j.onNext(t);
} catch (Throwable th2) {
th = th2;
}
if (j != Long.MAX_VALUE) {
this.m.a(1);
}
int i3 = this.f2840z + 1;
if (i3 == this.f2839y) {
this.f2840z = 0;
request((long) i3);
} else {
this.f2840z = i3;
}
synchronized (this) {
if (!this.f2837s) {
this.r = false;
return;
}
this.f2837s = false;
c();
return;
}
}
e(t);
c();
return;
}
e(t);
b();
return;
} else {
long j2 = this.v;
this.v = 1 + j2;
c<?> cVar = new c<>(this, j2);
CompositeSubscription compositeSubscription = this.o;
if (compositeSubscription == null) {
synchronized (this) {
compositeSubscription = this.o;
if (compositeSubscription == null) {
compositeSubscription = new CompositeSubscription();
this.o = compositeSubscription;
} else {
z2 = false;
}
}
if (z2) {
add(compositeSubscription);
}
}
compositeSubscription.a(cVar);
synchronized (this.t) {
c<?>[] cVarArr = this.u;
int length = cVarArr.length;
c<?>[] cVarArr2 = new c[(length + 1)];
System.arraycopy(cVarArr, 0, cVarArr2, 0, length);
cVarArr2[length] = cVar;
this.u = cVarArr2;
}
observable.i0(cVar);
b();
return;
}
} else {
return;
}
if (!z2) {
synchronized (this) {
this.r = false;
}
}
throw th;
}
}
public x0(boolean z2, int i) {
this.i = z2;
}
@Override // j0.k.b
public Object call(Object obj) {
Subscriber subscriber = (Subscriber) obj;
e eVar = new e(subscriber, this.i, Integer.MAX_VALUE);
d<T> dVar = new d<>(eVar);
eVar.m = dVar;
subscriber.add(eVar);
subscriber.setProducer(dVar);
return eVar;
}
}