* Removes and returns the next item in FIFO order, switching to a reversed * buffer when that is cheaper than shifting from the front of the array. * @returns {T | undefined} The head of the queue of `undefined` if this queue is empty.
()
| 59 | * @returns {T | undefined} The head of the queue of `undefined` if this queue is empty. |
| 60 | */ |
| 61 | dequeue() { |
| 62 | if (this._listReversed.length === 0) { |
| 63 | if (this._list.length === 0) return; |
| 64 | if (this._list.length === 1) return this._list.pop(); |
| 65 | if (this._list.length < 16) return this._list.shift(); |
| 66 | const temp = this._listReversed; |
| 67 | this._listReversed = this._list; |
| 68 | this._listReversed.reverse(); |
| 69 | this._list = temp; |
| 70 | } |
| 71 | return this._listReversed.pop(); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Removes the first matching item from whichever internal buffer currently |
no test coverage detected