treeSitterCopyWasmUnsizedStaticArray function

Uint8List? treeSitterCopyWasmUnsizedStaticArray(
  1. Uint8List memory,
  2. int startAddress,
  3. Iterable<int> allAddresses
)

Copies the static byte region ending at the nearest greater Wasm address.

Implementation

Uint8List? treeSitterCopyWasmUnsizedStaticArray(
  Uint8List memory,
  int startAddress,
  Iterable<int> allAddresses,
) {
  int? endAddress;
  for (final address in allAddresses) {
    if (address > startAddress &&
        (endAddress == null || address < endAddress)) {
      endAddress = address;
    }
  }
  if (endAddress == null) return null;
  if (startAddress < 0 || endAddress > memory.length) {
    throw const FormatException('Wasm static array is outside linear memory');
  }
  return Uint8List.fromList(memory.sublist(startAddress, endAddress));
}