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>}
|
* @type {Set<T>}
|
||||||
*/
|
*/
|
||||||
this._set = new Set(items);
|
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.
|
* 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() {
|
dequeue() {
|
||||||
const result = this._set[Symbol.iterator]().next();
|
let result = this._iterator.next();
|
||||||
if (result.done) return;
|
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);
|
this._set.delete(result.value);
|
||||||
return result.value;
|
return result.value;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue