Skip to content

Commit 5d6df88

Browse files
committed
improve(priority-queue): resize the array while initializing
1 parent 8ec5f4d commit 5d6df88

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

Diff for: packages/priority-queue/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export function createPriorityQueue<T>(
6666
*/
6767
function init(elements: ReadonlyArray<T>): void {
6868
_size = Math.max(0, elements.length)
69+
if (_tree.length <= _size) _tree.length = _size + 1
6970
for (let i = 0; i < _size; ++i) _tree[i + 1] = elements[i]
7071
for (let q = _size; q > 1; q -= 2) _down(q >> 1)
7172
}

0 commit comments

Comments
 (0)