mirror of https://github.com/webpack/webpack.git
Merge eaf527235a into 9f98d803c0
This commit is contained in:
commit
8fbce14d5b
|
|
@ -18,6 +18,11 @@ class Queue {
|
|||
* @type {Set<T>}
|
||||
*/
|
||||
this._set = new Set(items);
|
||||
/**
|
||||
* @private
|
||||
* @type {Iterator<T>}
|
||||
*/
|
||||
this._iterator = this._set[Symbol.iterator]();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -39,11 +44,16 @@ class Queue {
|
|||
|
||||
/**
|
||||
* Retrieves and removes the head of this queue.
|
||||
* @returns {T | undefined} The head of the queue of `undefined` if this queue is empty.
|
||||
* @returns {T | undefined} The head of the queue or `undefined` if this queue is empty.
|
||||
*/
|
||||
dequeue() {
|
||||
const result = this._set[Symbol.iterator]().next();
|
||||
if (result.done) return;
|
||||
let result = this._iterator.next();
|
||||
const isInvalidIterator = result.done && this._set.size > 0;
|
||||
if (isInvalidIterator) {
|
||||
this._iterator = this._set[Symbol.iterator]();
|
||||
result = this._iterator.next();
|
||||
}
|
||||
if (result.done) return undefined;
|
||||
this._set.delete(result.value);
|
||||
return result.value;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue