uint8ListCompare function

int uint8ListCompare(
  1. Uint8List a,
  2. Uint8List b
)

Compare two Uint8List

Implementation

int uint8ListCompare(Uint8List a, Uint8List b) {
  int i = 0;
  while (true) {
    final overA = i >= a.length;
    final overB = i >= b.length;
    if (overA && overB) {
      // both ends reached
      return 0;
    } else if (overA) {
      // a has no more data, b has data
      return -1;
    } else if (overB) {
      // b has no more data, a has data
      return 1;
    } else if (a[i] != b[i]) {
      // the number in this index doesn't match
      // (we don't use u8aa[i] - u8ab[i] since that doesn't match with localeCompare)
      return a[i] > b[i] ? 1 : -1;
    }
    i++;
  }
}