clear method Null safety

void clear()
override

Removes all elements in the queue. The size of the queue becomes zero.

Implementation

void clear() {
  var cursor = _sentinel._nextLink!;
  while (true) {
    var entry = cursor._asNonSentinelEntry();
    if (entry == null) break;
    cursor = cursor._nextLink!;
    entry
      .._nextLink = null
      .._previousLink = null
      .._queue = null;
  }
  _sentinel._nextLink = _sentinel;
  _sentinel._previousLink = _sentinel;
  _elementCount = 0;
}