ValueAt method

Pointer<Char> ValueAt(
  1. String key, [
  2. String? text
])

Returns the Pointer<Char> for the keyed slot key, optionally writing text into it.

Allocates the slot on first use. If text is null the existing string is returned; asserts that the slot has been initialised at least once.

Implementation

Pointer<Char> ValueAt(String key, [String? text]) {
  final slot = _StringSlotsKeyed.putIfAbsent(
    key, () => _StringSlots.length
  );

  _ensureStringSlotExists(slot);

  if (text != null) {
    return _writeStringToSlot(slot, text);
  }

  assert(
    _StringSlots[slot] != nullptr,
    '[TEMP] String.ValueAt("$key") used before initialization'
  );

  return _StringSlots[slot];
}