Rabbit-R1/android (non root)/java/sources/androidx/compose/runtime/snapshots/SnapshotKt.java

734 lines
43 KiB
Java
Raw Normal View History

2024-05-21 16:08:36 -05:00
package androidx.compose.runtime.snapshots;
import androidx.compose.runtime.AtomicInt;
import androidx.compose.runtime.SnapshotThreadLocal;
import androidx.compose.runtime.WeakReference;
import androidx.compose.runtime.collection.IdentityArraySet;
import androidx.exifinterface.media.ExifInterface;
import io.sentry.protocol.SentryStackFrame;
import io.sentry.protocol.SentryStackTrace;
import io.sentry.protocol.SentryThread;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import kotlin.KotlinNothingValueException;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.internal.InlineMarker;
import kotlin.jvm.internal.Intrinsics;
/* compiled from: Snapshot.kt */
@Metadata(d1 = {"\u0000\u0096\u0001\n\u0000\n\u0002\u0010\b\n\u0000\n\u0002\u0010!\n\u0002\u0018\u0002\n\u0002\u0010\"\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\t\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\t\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\r\n\u0002\u0010$\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0010\u0001\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\u0019\n\u0002\u0018\u0002\n\u0002\b\n\u001a\b\u0010)\u001a\u00020\bH\u0002\u001a6\u0010)\u001a\u0002H*\"\u0004\b\u0000\u0010*2!\u0010+\u001a\u001d\u0012\u0013\u0012\u00110\u0010¢\u0006\f\b\u0011\u0012\b\b\u0012\u0012\u0004\b\b(\u0013\u0012\u0004\u0012\u0002H*0\u000fH\u0002¢\u0006\u0002\u0010,\u001a\b\u0010-\u001a\u00020\bH\u0002\u001a4\u0010.\u001a\u00020\u00072\b\u0010/\u001a\u0004\u0018\u00010\u00072\u0016\b\u0002\u00100\u001a\u0010\u0012\u0004\u0012\u00020\u0006\u0012\u0004\u0012\u00020\b\u0018\u00010\u000f2\b\b\u0002\u00101\u001a\u000202H\u0002\u001a\u001f\u00103\u001a\u0002H*\"\b\b\u0000\u0010**\u0002042\u0006\u00105\u001a\u0002H*H\u0001¢\u0006\u0002\u00106\u001a'\u00103\u001a\u0002H*\"\b\b\u0000\u0010**\u0002042\u0006\u00105\u001a\u0002H*2\u0006\u00107\u001a\u00020\u0007H\u0001¢\u0006\u0002\u00108\u001a\b\u00109\u001a\u00020\u0007H\u0000\u001aL\u0010:\u001a\u0010\u0012\u0004\u0012\u00020\u0006\u0012\u0004\u0012\u00020\b\u0018\u00010\u000f2\u0014\u00100\u001a\u0010\u0012\u0004\u0012\u00020\u0006\u0012\u0004\u0012\u00020\b\u0018\u00010\u000f2\u0014\u0010;\u001a\u0010\u0012\u0004\u0012\u00020\u0006\u0012\u0004\u0012\u00020\b\u0018\u00010\u000f2\b\b\u0002\u0010<\u001a\u000202H\u0002\u001aB\u0010=\u001a\u0010\u0012\u0004\u0012\u00020\u0006\u0012\u0004\u0012\u00020\b\u0018\u00010\u000f2\u0014\u0010>\u001a\u0010\u0012\u0004\u0012\u00020\u0006\u0012\u0004\u0012\u00020\b\u0018\u00010\u000f2\u0014\u0010;\u001a\u0010\u0012\u0004\u0012\u00020\u0006\u0012\u0004\u0012\u00020\b\u0018\u00010\u000fH\u0002\u001a\u0018\u0010?\u001a\u00020\b2\u0006\u00107\u001a\u00020\u00072\u0006\u0010@\u001a\u00020\u0016H\u0001\u001a.\u0010A\u001a\u0010\u0012\u0004\u0012\u000204\u0012\u0004\u0012\u000204\u0018\u00010B2\u0006\u00109\u001a\u00020C2\u0006\u0010D\u001a\u00020C2\u0006\u0010E\u001a\u00020\u0010H\u0002\u001a\u0010\u0010F\u001a\u0002022\u0006\u0010@\u001a\u00020\u0016H\u0002\u001a\u0010\u0010G\u001a\u00020\b2\u0006\u0010@\u001a\u00020\u0016H\u0002\u001a\b\u0010H\u001a\u00020IH\u0002\u001a1\u0010J\u001a\u0004\u0018\u0001H*\"\b\b\u0000\u0010**\u0002042\u0006\u00105\u001a\u0002H*2\u0006\u0010K\u001a\u00020\u00012\u0006\u0010\u0013\u001a\u00020\u0010H\u0002¢\u0006\u0002\u0010L\u001a\u0010\u0010M\u001a\u00020\b2\u0006\u0010N\u001a\u00020\u0001H\u0000\u001a\b\u0010O\u001a\u00020IH\u0002\u001a%\u0010P\u001a\u0002H*\"\u0004\b\u0000\u0010*2\f\u0010+\u001a\b\u0012\u0004\u0012\u0002H*0QH\u0081\\u0001\u0000¢\u0006\u0002\u0010R\u001a>\u0010S\u001a\u0002H*\"\u0004\b\u0000\u0010*2\u0006\u0010T\u001a\u00020\u00072!\u0010+\u001a\u001d\u0012\u0013\u0012\u00110\u0010¢\u0006\f\b\u0011\u0012\b\b\u0012\u0012\u0004\b\b(\u0013\u0012\u0004\u0012\u0002H*0\u000fH\u0002¢\u0006\u0002\u0010U\u001a:\u0010V\u001a\u0002H*\"\b\b\u0000\u0010**\u00020\u00072!\u0010+\u001a\u001d\u0012\u0013\u0012\u00110\u0010¢\u0006\f\b\u0011\u0012\b\b\u0012\u0012\u0004\b\b(\u0013\u0012\u0004\u0012\u0002H*0\u000fH\u0002¢\u0006\u0002\u0010W\u001a\u0018\u0010X\u001a\u00020\u00012\u0006\u0010K\u001a\u00020\u00012\u0006\u0010\u0013\u001a\u00020\u0010H\u0000\u001a\u0012\u0010Y\u001a\u0004\u0018\u0001042\u0006\u0010@\u001a\u00020\u0016H\u0002\u001a \u0010Z\u001a\u0002022\u0006\u0010[\u001a\u0002042\u0006\u00107\u001a\u00020\u00012\u0006\u0010\u0013\u001a\u00020\u0010H\u0002\u001a \u0010Z\u001a\u0002022\u0006\u00109\u001a\u00020\u00012\u0006\u0010\\\u001a\u00020\u00012\u0006\u0010\u0013\u001a\u00020\u0010H\u0002\u001a\u0010\u0010]\u001
/* loaded from: classes.dex */
public final class SnapshotKt {
private static final int INVALID_SNAPSHOT = 0;
private static final AtomicReference<GlobalSnapshot> currentGlobalSnapshot;
private static int nextSnapshotId;
private static SnapshotIdSet openSnapshots;
private static AtomicInt pendingApplyObserverCount;
private static final Snapshot snapshotInitializer;
private static final Function1<SnapshotIdSet, Unit> emptyLambda = new Function1<SnapshotIdSet, Unit>() { // from class: androidx.compose.runtime.snapshots.SnapshotKt$emptyLambda$1
/* renamed from: invoke, reason: avoid collision after fix types in other method */
public final void invoke2(SnapshotIdSet it) {
Intrinsics.checkNotNullParameter(it, "it");
}
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(SnapshotIdSet snapshotIdSet) {
invoke2(snapshotIdSet);
return Unit.INSTANCE;
}
};
private static final SnapshotThreadLocal<Snapshot> threadSnapshot = new SnapshotThreadLocal<>();
private static final Object lock = new Object();
private static final SnapshotDoubleIndexHeap pinningTable = new SnapshotDoubleIndexHeap();
private static final SnapshotWeakSet<StateObject> extraStateObjects = new SnapshotWeakSet<>();
private static final List<Function2<Set<? extends Object>, Snapshot, Unit>> applyObservers = new ArrayList();
private static final List<Function1<Object, Unit>> globalWriteObservers = new ArrayList();
public static final Object getLock() {
return lock;
}
public static /* synthetic */ void getLock$annotations() {
}
public static final Snapshot getSnapshotInitializer() {
return snapshotInitializer;
}
public static /* synthetic */ void getSnapshotInitializer$annotations() {
}
public static final int trackPinning(int i, SnapshotIdSet invalid) {
int add;
Intrinsics.checkNotNullParameter(invalid, "invalid");
int lowest = invalid.lowest(i);
synchronized (getLock()) {
add = pinningTable.add(lowest);
}
return add;
}
public static final void releasePinningLocked(int i) {
pinningTable.remove(i);
}
public static final Snapshot currentSnapshot() {
Snapshot snapshot = threadSnapshot.get();
if (snapshot != null) {
return snapshot;
}
GlobalSnapshot globalSnapshot = currentGlobalSnapshot.get();
Intrinsics.checkNotNullExpressionValue(globalSnapshot, "currentGlobalSnapshot.get()");
return globalSnapshot;
}
static {
openSnapshots = SnapshotIdSet.INSTANCE.getEMPTY();
nextSnapshotId = 1;
int i = nextSnapshotId;
nextSnapshotId = i + 1;
GlobalSnapshot globalSnapshot = new GlobalSnapshot(i, SnapshotIdSet.INSTANCE.getEMPTY());
openSnapshots = openSnapshots.set(globalSnapshot.getId());
AtomicReference<GlobalSnapshot> atomicReference = new AtomicReference<>(globalSnapshot);
currentGlobalSnapshot = atomicReference;
GlobalSnapshot globalSnapshot2 = atomicReference.get();
Intrinsics.checkNotNullExpressionValue(globalSnapshot2, "currentGlobalSnapshot.get()");
snapshotInitializer = globalSnapshot2;
pendingApplyObserverCount = new AtomicInt(0);
}
public static /* synthetic */ Snapshot createTransparentSnapshotWithNoParentReadObserver$default(Snapshot snapshot, Function1 function1, boolean z, int i, Object obj) {
if ((i & 2) != 0) {
function1 = null;
}
if ((i & 4) != 0) {
z = false;
}
return createTransparentSnapshotWithNoParentReadObserver(snapshot, function1, z);
}
public static final Snapshot createTransparentSnapshotWithNoParentReadObserver(Snapshot snapshot, Function1<Object, Unit> function1, boolean z) {
boolean z2 = snapshot instanceof MutableSnapshot;
if (z2 || snapshot == null) {
return new TransparentObserverMutableSnapshot(z2 ? (MutableSnapshot) snapshot : null, function1, null, false, z);
}
return new TransparentObserverSnapshot(snapshot, function1, false, z);
}
public static /* synthetic */ Function1 mergedReadObserver$default(Function1 function1, Function1 function12, boolean z, int i, Object obj) {
if ((i & 4) != 0) {
z = true;
}
return mergedReadObserver(function1, function12, z);
}
public static final Function1<Object, Unit> mergedReadObserver(final Function1<Object, Unit> function1, final Function1<Object, Unit> function12, boolean z) {
if (!z) {
function12 = null;
}
if (function1 == null || function12 == null || Intrinsics.areEqual(function1, function12)) {
return function1 == null ? function12 : function1;
}
return new Function1<Object, Unit>() { // from class: androidx.compose.runtime.snapshots.SnapshotKt$mergedReadObserver$1
/* JADX INFO: Access modifiers changed from: package-private */
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
{
super(1);
}
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(Object obj) {
invoke2(obj);
return Unit.INSTANCE;
}
/* renamed from: invoke, reason: avoid collision after fix types in other method */
public final void invoke2(Object state) {
Intrinsics.checkNotNullParameter(state, "state");
function1.invoke(state);
function12.invoke(state);
}
};
}
public static final Function1<Object, Unit> mergedWriteObserver(final Function1<Object, Unit> function1, final Function1<Object, Unit> function12) {
if (function1 == null || function12 == null || Intrinsics.areEqual(function1, function12)) {
return function1 == null ? function12 : function1;
}
return new Function1<Object, Unit>() { // from class: androidx.compose.runtime.snapshots.SnapshotKt$mergedWriteObserver$1
/* JADX INFO: Access modifiers changed from: package-private */
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
{
super(1);
}
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(Object obj) {
invoke2(obj);
return Unit.INSTANCE;
}
/* renamed from: invoke, reason: avoid collision after fix types in other method */
public final void invoke2(Object state) {
Intrinsics.checkNotNullParameter(state, "state");
function1.invoke(state);
function12.invoke(state);
}
};
}
public static final <T> T sync(Function0<? extends T> block) {
T invoke;
Intrinsics.checkNotNullParameter(block, "block");
synchronized (getLock()) {
try {
invoke = block.invoke();
InlineMarker.finallyStart(1);
} catch (Throwable th) {
InlineMarker.finallyStart(1);
InlineMarker.finallyEnd(1);
throw th;
}
}
InlineMarker.finallyEnd(1);
return invoke;
}
public static final <T> T takeNewGlobalSnapshot(Snapshot snapshot, Function1<? super SnapshotIdSet, ? extends T> function1) {
T invoke = function1.invoke(openSnapshots.clear(snapshot.getId()));
synchronized (getLock()) {
int i = nextSnapshotId;
nextSnapshotId = i + 1;
openSnapshots = openSnapshots.clear(snapshot.getId());
currentGlobalSnapshot.set(new GlobalSnapshot(i, openSnapshots));
snapshot.dispose();
openSnapshots = openSnapshots.set(i);
Unit unit = Unit.INSTANCE;
}
return invoke;
}
public static final <T> T advanceGlobalSnapshot(Function1<? super SnapshotIdSet, ? extends T> function1) {
GlobalSnapshot globalSnapshot;
IdentityArraySet<StateObject> modified$runtime_release;
T t;
List mutableList;
Snapshot snapshot = snapshotInitializer;
Intrinsics.checkNotNull(snapshot, "null cannot be cast to non-null type androidx.compose.runtime.snapshots.GlobalSnapshot");
synchronized (getLock()) {
globalSnapshot = currentGlobalSnapshot.get();
Intrinsics.checkNotNullExpressionValue(globalSnapshot, "currentGlobalSnapshot.get()");
modified$runtime_release = globalSnapshot.getModified$runtime_release();
if (modified$runtime_release != null) {
pendingApplyObserverCount.add(1);
}
t = (T) takeNewGlobalSnapshot(globalSnapshot, function1);
}
if (modified$runtime_release != null) {
try {
synchronized (getLock()) {
mutableList = CollectionsKt.toMutableList((Collection) applyObservers);
}
int size = mutableList.size();
for (int i = 0; i < size; i++) {
((Function2) mutableList.get(i)).invoke(modified$runtime_release, globalSnapshot);
}
} finally {
pendingApplyObserverCount.add(-1);
}
}
synchronized (getLock()) {
checkAndOverwriteUnusedRecordsLocked();
if (modified$runtime_release != null) {
Object[] values = modified$runtime_release.getValues();
int size2 = modified$runtime_release.size();
for (int i2 = 0; i2 < size2; i2++) {
Object obj = values[i2];
Intrinsics.checkNotNull(obj, "null cannot be cast to non-null type T of androidx.compose.runtime.collection.IdentityArraySet");
processForUnusedRecordsLocked((StateObject) obj);
}
Unit unit = Unit.INSTANCE;
}
}
return t;
}
public static final void advanceGlobalSnapshot() {
advanceGlobalSnapshot(new Function1<SnapshotIdSet, Unit>() { // from class: androidx.compose.runtime.snapshots.SnapshotKt$advanceGlobalSnapshot$3
/* renamed from: invoke, reason: avoid collision after fix types in other method */
public final void invoke2(SnapshotIdSet it) {
Intrinsics.checkNotNullParameter(it, "it");
}
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(SnapshotIdSet snapshotIdSet) {
invoke2(snapshotIdSet);
return Unit.INSTANCE;
}
});
}
public static final <T extends Snapshot> T takeNewSnapshot(final Function1<? super SnapshotIdSet, ? extends T> function1) {
return (T) advanceGlobalSnapshot(new Function1<SnapshotIdSet, T>() { // from class: androidx.compose.runtime.snapshots.SnapshotKt$takeNewSnapshot$1
/* JADX INFO: Access modifiers changed from: package-private */
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
/* JADX WARN: Multi-variable type inference failed */
{
super(1);
}
/* JADX WARN: Incorrect return type in method signature: (Landroidx/compose/runtime/snapshots/SnapshotIdSet;)TT; */
@Override // kotlin.jvm.functions.Function1
public final Snapshot invoke(SnapshotIdSet invalid) {
SnapshotIdSet snapshotIdSet;
Intrinsics.checkNotNullParameter(invalid, "invalid");
Snapshot snapshot = (Snapshot) function1.invoke(invalid);
synchronized (SnapshotKt.getLock()) {
snapshotIdSet = SnapshotKt.openSnapshots;
SnapshotKt.openSnapshots = snapshotIdSet.set(snapshot.getId());
Unit unit = Unit.INSTANCE;
}
return snapshot;
}
});
}
public static final void validateOpen(Snapshot snapshot) {
if (!openSnapshots.get(snapshot.getId())) {
throw new IllegalStateException("Snapshot is not open".toString());
}
}
private static final boolean valid(int i, int i2, SnapshotIdSet snapshotIdSet) {
return (i2 == 0 || i2 > i || snapshotIdSet.get(i2)) ? false : true;
}
private static final boolean valid(StateRecord stateRecord, int i, SnapshotIdSet snapshotIdSet) {
return valid(i, stateRecord.getSnapshotId(), snapshotIdSet);
}
public static final <T extends StateRecord> T readable(T t, int i, SnapshotIdSet snapshotIdSet) {
T t2 = null;
while (t != null) {
if (valid(t, i, snapshotIdSet) && (t2 == null || t2.getSnapshotId() < t.getSnapshotId())) {
t2 = t;
}
t = (T) t.getNext();
}
if (t2 != null) {
return t2;
}
return null;
}
public static final <T extends StateRecord> T readable(T t, StateObject state) {
T t2;
Intrinsics.checkNotNullParameter(t, "<this>");
Intrinsics.checkNotNullParameter(state, "state");
Snapshot current = Snapshot.INSTANCE.getCurrent();
Function1<Object, Unit> readObserver$runtime_release = current.getReadObserver$runtime_release();
if (readObserver$runtime_release != null) {
readObserver$runtime_release.invoke(state);
}
T t3 = (T) readable(t, current.getId(), current.getInvalid());
if (t3 != null) {
return t3;
}
synchronized (getLock()) {
Snapshot current2 = Snapshot.INSTANCE.getCurrent();
StateRecord firstStateRecord = state.getFirstStateRecord();
Intrinsics.checkNotNull(firstStateRecord, "null cannot be cast to non-null type T of androidx.compose.runtime.snapshots.SnapshotKt.readable$lambda$9");
t2 = (T) readable(firstStateRecord, current2.getId(), current2.getInvalid());
if (t2 == null) {
readError();
throw new KotlinNothingValueException();
}
}
return t2;
}
public static final <T extends StateRecord> T readable(T t, StateObject state, Snapshot snapshot) {
Intrinsics.checkNotNullParameter(t, "<this>");
Intrinsics.checkNotNullParameter(state, "state");
Intrinsics.checkNotNullParameter(snapshot, "snapshot");
Function1<Object, Unit> readObserver$runtime_release = snapshot.getReadObserver$runtime_release();
if (readObserver$runtime_release != null) {
readObserver$runtime_release.invoke(state);
}
T t2 = (T) readable(t, snapshot.getId(), snapshot.getInvalid());
if (t2 != null) {
return t2;
}
readError();
throw new KotlinNothingValueException();
}
public static final Void readError() {
throw new IllegalStateException("Reading a state that was created after the snapshot was taken or in a snapshot that has not yet been applied".toString());
}
private static final StateRecord usedLocked(StateObject stateObject) {
int lowestOrDefault = pinningTable.lowestOrDefault(nextSnapshotId) - 1;
SnapshotIdSet empty = SnapshotIdSet.INSTANCE.getEMPTY();
StateRecord stateRecord = null;
for (StateRecord firstStateRecord = stateObject.getFirstStateRecord(); firstStateRecord != null; firstStateRecord = firstStateRecord.getNext()) {
if (firstStateRecord.getSnapshotId() == 0) {
return firstStateRecord;
}
if (valid(firstStateRecord, lowestOrDefault, empty)) {
if (stateRecord != null) {
return firstStateRecord.getSnapshotId() < stateRecord.getSnapshotId() ? firstStateRecord : stateRecord;
}
stateRecord = firstStateRecord;
}
}
return null;
}
private static final boolean overwriteUnusedRecordsLocked(StateObject stateObject) {
StateRecord stateRecord;
int lowestOrDefault = pinningTable.lowestOrDefault(nextSnapshotId);
StateRecord stateRecord2 = null;
StateRecord stateRecord3 = null;
int i = 0;
for (StateRecord firstStateRecord = stateObject.getFirstStateRecord(); firstStateRecord != null; firstStateRecord = firstStateRecord.getNext()) {
int snapshotId = firstStateRecord.getSnapshotId();
if (snapshotId != 0) {
if (snapshotId >= lowestOrDefault) {
i++;
} else if (stateRecord2 == null) {
i++;
stateRecord2 = firstStateRecord;
} else {
if (firstStateRecord.getSnapshotId() < stateRecord2.getSnapshotId()) {
stateRecord = stateRecord2;
stateRecord2 = firstStateRecord;
} else {
stateRecord = firstStateRecord;
}
if (stateRecord3 == null) {
stateRecord3 = stateObject.getFirstStateRecord();
StateRecord stateRecord4 = stateRecord3;
while (true) {
if (stateRecord3 == null) {
stateRecord3 = stateRecord4;
break;
}
if (stateRecord3.getSnapshotId() >= lowestOrDefault) {
break;
}
if (stateRecord4.getSnapshotId() < stateRecord3.getSnapshotId()) {
stateRecord4 = stateRecord3;
}
stateRecord3 = stateRecord3.getNext();
}
}
stateRecord2.setSnapshotId$runtime_release(0);
stateRecord2.assign(stateRecord3);
stateRecord2 = stateRecord;
}
}
}
return i > 1;
}
private static final StateRecord findYoungestOr(StateRecord stateRecord, Function1<? super StateRecord, Boolean> function1) {
StateRecord stateRecord2 = stateRecord;
while (stateRecord != null) {
if (function1.invoke(stateRecord).booleanValue()) {
return stateRecord;
}
if (stateRecord2.getSnapshotId() < stateRecord.getSnapshotId()) {
stateRecord2 = stateRecord;
}
stateRecord = stateRecord.getNext();
}
return stateRecord2;
}
public static final void processForUnusedRecordsLocked(StateObject stateObject) {
if (overwriteUnusedRecordsLocked(stateObject)) {
extraStateObjects.add(stateObject);
}
}
public static final <T extends StateRecord> T writableRecord(T t, StateObject state, Snapshot snapshot) {
Intrinsics.checkNotNullParameter(t, "<this>");
Intrinsics.checkNotNullParameter(state, "state");
Intrinsics.checkNotNullParameter(snapshot, "snapshot");
if (snapshot.getReadOnly()) {
snapshot.mo2289recordModified$runtime_release(state);
}
T t2 = (T) readable(t, snapshot.getId(), snapshot.getInvalid());
if (t2 == null) {
readError();
throw new KotlinNothingValueException();
}
if (t2.getSnapshotId() == snapshot.getId()) {
return t2;
}
T t3 = (T) newWritableRecord(t2, state, snapshot);
snapshot.mo2289recordModified$runtime_release(state);
return t3;
}
public static final <T extends StateRecord> T overwritableRecord(T t, StateObject state, Snapshot snapshot, T candidate) {
T t2;
Intrinsics.checkNotNullParameter(t, "<this>");
Intrinsics.checkNotNullParameter(state, "state");
Intrinsics.checkNotNullParameter(snapshot, "snapshot");
Intrinsics.checkNotNullParameter(candidate, "candidate");
if (snapshot.getReadOnly()) {
snapshot.mo2289recordModified$runtime_release(state);
}
int id = snapshot.getId();
if (candidate.getSnapshotId() == id) {
return candidate;
}
synchronized (getLock()) {
t2 = (T) newOverwritableRecordLocked(t, state);
}
t2.setSnapshotId$runtime_release(id);
snapshot.mo2289recordModified$runtime_release(state);
return t2;
}
private static final <T extends StateRecord> T newWritableRecordLocked(T t, StateObject stateObject, Snapshot snapshot) {
T t2 = (T) newOverwritableRecordLocked(t, stateObject);
t2.assign(t);
t2.setSnapshotId$runtime_release(snapshot.getId());
return t2;
}
public static final <T extends StateRecord> T newOverwritableRecordLocked(T t, StateObject state) {
Intrinsics.checkNotNullParameter(t, "<this>");
Intrinsics.checkNotNullParameter(state, "state");
T t2 = (T) usedLocked(state);
if (t2 != null) {
t2.setSnapshotId$runtime_release(Integer.MAX_VALUE);
return t2;
}
T t3 = (T) t.create();
t3.setSnapshotId$runtime_release(Integer.MAX_VALUE);
t3.setNext$runtime_release(state.getFirstStateRecord());
Intrinsics.checkNotNull(t3, "null cannot be cast to non-null type T of androidx.compose.runtime.snapshots.SnapshotKt.newOverwritableRecordLocked$lambda$15");
state.prependStateRecord(t3);
Intrinsics.checkNotNull(t3, "null cannot be cast to non-null type T of androidx.compose.runtime.snapshots.SnapshotKt.newOverwritableRecordLocked");
return t3;
}
public static final void notifyWrite(Snapshot snapshot, StateObject state) {
Intrinsics.checkNotNullParameter(snapshot, "snapshot");
Intrinsics.checkNotNullParameter(state, "state");
snapshot.setWriteCount$runtime_release(snapshot.getWriteCount() + 1);
Function1<Object, Unit> writeObserver$runtime_release = snapshot.getWriteObserver$runtime_release();
if (writeObserver$runtime_release != null) {
writeObserver$runtime_release.invoke(state);
}
}
public static final <T extends StateRecord, R> R writable(T t, StateObject state, Function1<? super T, ? extends R> block) {
Snapshot current;
R invoke;
Intrinsics.checkNotNullParameter(t, "<this>");
Intrinsics.checkNotNullParameter(state, "state");
Intrinsics.checkNotNullParameter(block, "block");
getSnapshotInitializer();
synchronized (getLock()) {
try {
current = Snapshot.INSTANCE.getCurrent();
invoke = block.invoke(writableRecord(t, state, current));
InlineMarker.finallyStart(1);
} catch (Throwable th) {
InlineMarker.finallyStart(1);
InlineMarker.finallyEnd(1);
throw th;
}
}
InlineMarker.finallyEnd(1);
notifyWrite(current, state);
return invoke;
}
public static final <T extends StateRecord, R> R overwritable(T t, StateObject state, T candidate, Function1<? super T, ? extends R> block) {
Snapshot current;
R invoke;
Intrinsics.checkNotNullParameter(t, "<this>");
Intrinsics.checkNotNullParameter(state, "state");
Intrinsics.checkNotNullParameter(candidate, "candidate");
Intrinsics.checkNotNullParameter(block, "block");
getSnapshotInitializer();
synchronized (getLock()) {
try {
current = Snapshot.INSTANCE.getCurrent();
invoke = block.invoke(overwritableRecord(t, state, current, candidate));
InlineMarker.finallyStart(1);
} catch (Throwable th) {
InlineMarker.finallyStart(1);
InlineMarker.finallyEnd(1);
throw th;
}
}
InlineMarker.finallyEnd(1);
notifyWrite(current, state);
return invoke;
}
public static final Map<StateRecord, StateRecord> optimisticMerges(MutableSnapshot mutableSnapshot, MutableSnapshot mutableSnapshot2, SnapshotIdSet snapshotIdSet) {
StateRecord readable;
IdentityArraySet<StateObject> modified$runtime_release = mutableSnapshot2.getModified$runtime_release();
int id = mutableSnapshot.getId();
if (modified$runtime_release == null) {
return null;
}
SnapshotIdSet or = mutableSnapshot2.getInvalid().set(mutableSnapshot2.getId()).or(mutableSnapshot2.getPreviousIds());
Object[] values = modified$runtime_release.getValues();
int size = modified$runtime_release.size();
HashMap hashMap = null;
for (int i = 0; i < size; i++) {
Object obj = values[i];
Intrinsics.checkNotNull(obj, "null cannot be cast to non-null type T of androidx.compose.runtime.collection.IdentityArraySet");
StateObject stateObject = (StateObject) obj;
StateRecord firstStateRecord = stateObject.getFirstStateRecord();
StateRecord readable2 = readable(firstStateRecord, id, snapshotIdSet);
if (readable2 != null && (readable = readable(firstStateRecord, id, or)) != null && !Intrinsics.areEqual(readable2, readable)) {
StateRecord readable3 = readable(firstStateRecord, mutableSnapshot2.getId(), mutableSnapshot2.getInvalid());
if (readable3 == null) {
readError();
throw new KotlinNothingValueException();
}
StateRecord mergeRecords = stateObject.mergeRecords(readable, readable2, readable3);
if (mergeRecords == null) {
return null;
}
HashMap hashMap2 = hashMap;
if (hashMap2 == null) {
hashMap = new HashMap();
hashMap2 = hashMap;
}
hashMap2.put(readable2, mergeRecords);
}
}
return hashMap;
}
public static final Void reportReadonlySnapshotWrite() {
throw new IllegalStateException("Cannot modify a state object in a read-only snapshot".toString());
}
public static final <T extends StateRecord> T current(T r, Snapshot snapshot) {
Intrinsics.checkNotNullParameter(r, "r");
Intrinsics.checkNotNullParameter(snapshot, "snapshot");
T t = (T) readable(r, snapshot.getId(), snapshot.getInvalid());
if (t != null) {
return t;
}
readError();
throw new KotlinNothingValueException();
}
public static final <T extends StateRecord> T current(T r) {
T t;
Intrinsics.checkNotNullParameter(r, "r");
Snapshot current = Snapshot.INSTANCE.getCurrent();
T t2 = (T) readable(r, current.getId(), current.getInvalid());
if (t2 != null) {
return t2;
}
synchronized (getLock()) {
Snapshot current2 = Snapshot.INSTANCE.getCurrent();
t = (T) readable(r, current2.getId(), current2.getInvalid());
}
if (t != null) {
return t;
}
readError();
throw new KotlinNothingValueException();
}
public static final <T extends StateRecord, R> R withCurrent(T t, Function1<? super T, ? extends R> block) {
Intrinsics.checkNotNullParameter(t, "<this>");
Intrinsics.checkNotNullParameter(block, "block");
return block.invoke(current(t));
}
public static final SnapshotIdSet addRange(SnapshotIdSet snapshotIdSet, int i, int i2) {
Intrinsics.checkNotNullParameter(snapshotIdSet, "<this>");
while (i < i2) {
snapshotIdSet = snapshotIdSet.set(i);
i++;
}
return snapshotIdSet;
}
public static final void checkAndOverwriteUnusedRecordsLocked() {
SnapshotWeakSet<StateObject> snapshotWeakSet = extraStateObjects;
int size = snapshotWeakSet.getSize();
int i = 0;
int i2 = 0;
while (true) {
if (i >= size) {
break;
}
WeakReference<StateObject> weakReference = snapshotWeakSet.getValues$runtime_release()[i];
if ((weakReference != null ? weakReference.get() : null) != null && !(!overwriteUnusedRecordsLocked((StateObject) r5))) {
if (i2 != i) {
snapshotWeakSet.getValues$runtime_release()[i2] = weakReference;
snapshotWeakSet.getHashes()[i2] = snapshotWeakSet.getHashes()[i];
}
i2++;
}
i++;
}
for (int i3 = i2; i3 < size; i3++) {
snapshotWeakSet.getValues$runtime_release()[i3] = null;
snapshotWeakSet.getHashes()[i3] = 0;
}
if (i2 != size) {
snapshotWeakSet.setSize$runtime_release(i2);
}
}
public static final <T extends StateRecord> T newWritableRecord(T t, StateObject state, Snapshot snapshot) {
T t2;
Intrinsics.checkNotNullParameter(t, "<this>");
Intrinsics.checkNotNullParameter(state, "state");
Intrinsics.checkNotNullParameter(snapshot, "snapshot");
synchronized (getLock()) {
t2 = (T) newWritableRecordLocked(t, state, snapshot);
}
return t2;
}
public static final <T extends StateRecord, R> R writable(T t, StateObject state, Snapshot snapshot, Function1<? super T, ? extends R> block) {
R invoke;
Intrinsics.checkNotNullParameter(t, "<this>");
Intrinsics.checkNotNullParameter(state, "state");
Intrinsics.checkNotNullParameter(snapshot, "snapshot");
Intrinsics.checkNotNullParameter(block, "block");
synchronized (getLock()) {
try {
invoke = block.invoke(writableRecord(t, state, snapshot));
InlineMarker.finallyStart(1);
} catch (Throwable th) {
InlineMarker.finallyStart(1);
InlineMarker.finallyEnd(1);
throw th;
}
}
InlineMarker.finallyEnd(1);
notifyWrite(snapshot, state);
return invoke;
}
}