writeUnsignedArray method

void writeUnsignedArray(
  1. int id,
  2. List<int> values, [
  3. int? count
])

Writes an array of unsigned integers (CORELIB_PLAN §4.7) — the first count of values, all of them when omitted, so an InlineInt64Array's storage and length go out as they are. The declared element width (u8..u64) is an API concern only; the wire carries varints.

Every element goes out as given; writeUnsignedArrayInRange is the writer that bounds them by a declared width.

Implementation

void writeUnsignedArray(int id, List<int> values, [int? count]) {
  _writeHeader(id, WireType.arrayUnsigned);
  final n = _countOf(count, values.length);
  _writeVarint(n);
  var p = _pos;
  // Bulk fast path: one capacity check for the whole array, then a word-wise
  // varint per element ([_putVarint]) with the position kept in a local — no
  // per-element field reload and no per-byte bounds check.
  //
  // The `is Int64List` arm exists because `List<int>` is an *interface* call
  // per element; promoting to the concrete type lets AOT inline the load.
  final buf = _buf;
  if (p + n * 10 <= buf.length) {
    final bd = _bufData;
    if (values is Int64List) {
      for (var k = 0; k < n; k++) {
        p = _putVarint(buf, bd, p, values[k]);
      }
    } else {
      for (var k = 0; k < n; k++) {
        p = _putVarint(buf, bd, p, values[k]);
      }
    }
    _pos = p;
  } else {
    for (var k = 0; k < n; k++) {
      _writeVarint(values[k]);
    }
  }
}