PointerTo method
Allocates or syncs value to a tracked slot at key.
Implementation
P PointerTo(X value, [String? key]) {
if (!value.structRequiresOriginalPointer) {
String baseKey = getBaseKey(value, slotKey(key));
value.$state.allocKey = baseKey;
final p = At(baseKey);
value.structAllocateInto(temp, p, baseKey);
value.structSyncInto(temp, p, baseKey);
return p;
}
final op = value.originalPointer;
if (op != null) {
String allocKey = value.$state.allocKey ??= '<CHILD-POINTER>';
if (value.$state.isFirstSync) {
if (value.$state.isDisposed) return op;
if (!temp.doSync) return op;
// full sync once to push pre-promotion Dart state to memory
temp.debugSyncInfo('[SYNC] ${value.structName} first sync into $allocKey');
value.structSyncInto(temp, op, allocKey);
value.$state.isFirstSync = false;
} else {
// already live, setters handle write-through, skip full sync
temp.debugSyncInfo('[SYNC] ${value.structName} skipping sync (live) $allocKey');
}
return op;
}
if (value.$state.isDisposed) {
throw StateError('You are trying to allocate disposed object!');
}
String baseKey = getBaseKeyWithId(value, slotKey(key));
temp.debugSyncInfo('[SYNC] ${value.structName} allocate into $baseKey');
value.$state.allocKey = baseKey;
final p = At(baseKey);
value.structAllocateInto(temp, p, baseKey);
value.structSyncInto(temp, p, baseKey);
value.originalPointer = p;
return p;
}