memEquals function

bool memEquals(
  1. Uint8List x,
  2. Uint8List y
)

Compares two Uint8Lists by comparing 8 bytes at a time.

Implementation

bool memEquals(Uint8List x, Uint8List y) {
  if (identical(x, y)) return true;
  if (x.lengthInBytes != y.lengthInBytes) return false;

  var words = x.lengthInBytes ~/ 8; // number of full words
  var xW = x.buffer.asUint64List(0, words);
  var yW = y.buffer.asUint64List(0, words);

  // compare words
  for (var i = 0; i < xW.length; i += 1) {
    if (xW[i] != yW[i]) return false;
  }

  // compare remaining bytes
  for (var i = words * 8; i < x.lengthInBytes; i += 1) {
    if (x[i] != y[i]) return false;
  }

  return true; // no diff, they are equal
}