Files
rr3-apk/decompiled/sources/kotlinx/coroutines/internal/ThreadSafeHeap.java
Daniel Elliott f9d20bb3fc Add decompiled APK source code (JADX)
- 28,932 files
- Full Java source code
- Smali files
- Resources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-18 14:52:23 -08:00

196 lines
6.8 KiB
Java

package kotlinx.coroutines.internal;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import kotlin.jvm.internal.Intrinsics;
/* loaded from: classes5.dex */
public class ThreadSafeHeap {
public static final AtomicIntegerFieldUpdater _size$FU = AtomicIntegerFieldUpdater.newUpdater(ThreadSafeHeap.class, "_size");
private volatile int _size;
public ThreadSafeHeapNode[] a;
public final ThreadSafeHeapNode peek() {
ThreadSafeHeapNode firstImpl;
synchronized (this) {
firstImpl = firstImpl();
}
return firstImpl;
}
public final boolean remove(ThreadSafeHeapNode threadSafeHeapNode) {
boolean z;
synchronized (this) {
if (threadSafeHeapNode.getHeap() == null) {
z = false;
} else {
removeAtImpl(threadSafeHeapNode.getIndex());
z = true;
}
}
return z;
}
public final ThreadSafeHeapNode removeFirstOrNull() {
ThreadSafeHeapNode removeAtImpl;
synchronized (this) {
removeAtImpl = getSize() > 0 ? removeAtImpl(0) : null;
}
return removeAtImpl;
}
public final int getSize() {
return _size$FU.get(this);
}
public final void setSize(int i) {
_size$FU.set(this, i);
}
public final boolean isEmpty() {
return getSize() == 0;
}
public final ThreadSafeHeapNode firstImpl() {
ThreadSafeHeapNode[] threadSafeHeapNodeArr = this.a;
if (threadSafeHeapNodeArr != null) {
return threadSafeHeapNodeArr[0];
}
return null;
}
public final ThreadSafeHeapNode removeAtImpl(int i) {
ThreadSafeHeapNode[] threadSafeHeapNodeArr = this.a;
Intrinsics.checkNotNull(threadSafeHeapNodeArr);
setSize(getSize() - 1);
if (i < getSize()) {
swap(i, getSize());
int i2 = (i - 1) / 2;
if (i > 0) {
ThreadSafeHeapNode threadSafeHeapNode = threadSafeHeapNodeArr[i];
Intrinsics.checkNotNull(threadSafeHeapNode);
ThreadSafeHeapNode threadSafeHeapNode2 = threadSafeHeapNodeArr[i2];
Intrinsics.checkNotNull(threadSafeHeapNode2);
if (((Comparable) threadSafeHeapNode).compareTo(threadSafeHeapNode2) < 0) {
swap(i, i2);
siftUpFrom(i2);
}
}
siftDownFrom(i);
}
ThreadSafeHeapNode threadSafeHeapNode3 = threadSafeHeapNodeArr[getSize()];
Intrinsics.checkNotNull(threadSafeHeapNode3);
threadSafeHeapNode3.setHeap(null);
threadSafeHeapNode3.setIndex(-1);
threadSafeHeapNodeArr[getSize()] = null;
return threadSafeHeapNode3;
}
public final void addImpl(ThreadSafeHeapNode threadSafeHeapNode) {
threadSafeHeapNode.setHeap(this);
ThreadSafeHeapNode[] realloc = realloc();
int size = getSize();
setSize(size + 1);
realloc[size] = threadSafeHeapNode;
threadSafeHeapNode.setIndex(size);
siftUpFrom(size);
}
public final void siftUpFrom(int i) {
while (i > 0) {
ThreadSafeHeapNode[] threadSafeHeapNodeArr = this.a;
Intrinsics.checkNotNull(threadSafeHeapNodeArr);
int i2 = (i - 1) / 2;
ThreadSafeHeapNode threadSafeHeapNode = threadSafeHeapNodeArr[i2];
Intrinsics.checkNotNull(threadSafeHeapNode);
ThreadSafeHeapNode threadSafeHeapNode2 = threadSafeHeapNodeArr[i];
Intrinsics.checkNotNull(threadSafeHeapNode2);
if (((Comparable) threadSafeHeapNode).compareTo(threadSafeHeapNode2) <= 0) {
return;
}
swap(i, i2);
i = i2;
}
}
/* JADX WARN: Code restructure failed: missing block: B:6:0x0028, code lost:
if (((java.lang.Comparable) r3).compareTo(r4) < 0) goto L11;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public final void siftDownFrom(int r6) {
/*
r5 = this;
L0:
int r0 = r6 * 2
int r1 = r0 + 1
int r2 = r5.getSize()
if (r1 < r2) goto Lb
return
Lb:
kotlinx.coroutines.internal.ThreadSafeHeapNode[] r2 = r5.a
kotlin.jvm.internal.Intrinsics.checkNotNull(r2)
int r0 = r0 + 2
int r3 = r5.getSize()
if (r0 >= r3) goto L2b
r3 = r2[r0]
kotlin.jvm.internal.Intrinsics.checkNotNull(r3)
java.lang.Comparable r3 = (java.lang.Comparable) r3
r4 = r2[r1]
kotlin.jvm.internal.Intrinsics.checkNotNull(r4)
int r3 = r3.compareTo(r4)
if (r3 >= 0) goto L2b
goto L2c
L2b:
r0 = r1
L2c:
r1 = r2[r6]
kotlin.jvm.internal.Intrinsics.checkNotNull(r1)
java.lang.Comparable r1 = (java.lang.Comparable) r1
r2 = r2[r0]
kotlin.jvm.internal.Intrinsics.checkNotNull(r2)
int r1 = r1.compareTo(r2)
if (r1 > 0) goto L3f
return
L3f:
r5.swap(r6, r0)
r6 = r0
goto L0
*/
throw new UnsupportedOperationException("Method not decompiled: kotlinx.coroutines.internal.ThreadSafeHeap.siftDownFrom(int):void");
}
public final ThreadSafeHeapNode[] realloc() {
ThreadSafeHeapNode[] threadSafeHeapNodeArr = this.a;
if (threadSafeHeapNodeArr == null) {
ThreadSafeHeapNode[] threadSafeHeapNodeArr2 = new ThreadSafeHeapNode[4];
this.a = threadSafeHeapNodeArr2;
return threadSafeHeapNodeArr2;
}
if (getSize() < threadSafeHeapNodeArr.length) {
return threadSafeHeapNodeArr;
}
Object[] copyOf = Arrays.copyOf(threadSafeHeapNodeArr, getSize() * 2);
Intrinsics.checkNotNullExpressionValue(copyOf, "copyOf(this, newSize)");
ThreadSafeHeapNode[] threadSafeHeapNodeArr3 = (ThreadSafeHeapNode[]) copyOf;
this.a = threadSafeHeapNodeArr3;
return threadSafeHeapNodeArr3;
}
public final void swap(int i, int i2) {
ThreadSafeHeapNode[] threadSafeHeapNodeArr = this.a;
Intrinsics.checkNotNull(threadSafeHeapNodeArr);
ThreadSafeHeapNode threadSafeHeapNode = threadSafeHeapNodeArr[i2];
Intrinsics.checkNotNull(threadSafeHeapNode);
ThreadSafeHeapNode threadSafeHeapNode2 = threadSafeHeapNodeArr[i];
Intrinsics.checkNotNull(threadSafeHeapNode2);
threadSafeHeapNodeArr[i] = threadSafeHeapNode;
threadSafeHeapNodeArr[i2] = threadSafeHeapNode2;
threadSafeHeapNode.setIndex(i);
threadSafeHeapNode2.setIndex(i2);
}
}