From e290352c6b9fd3bc7fa4b8ea2cc2000fb20fdec7 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Thu, 9 May 2024 21:31:48 -0700 Subject: [PATCH] fix: revert DepsQueue to re-sort on pop() (#7499) --- .../arborist/lib/arborist/build-ideal-tree.js | 38 ++++--------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/workspaces/arborist/lib/arborist/build-ideal-tree.js b/workspaces/arborist/lib/arborist/build-ideal-tree.js index d0d159976c5db..7808a4b0f86f1 100644 --- a/workspaces/arborist/lib/arborist/build-ideal-tree.js +++ b/workspaces/arborist/lib/arborist/build-ideal-tree.js @@ -53,48 +53,26 @@ const _addNodeToTrashList = Symbol.for('addNodeToTrashList') // they'll affect things deeper in, then alphabetical for consistency between // installs class DepsQueue { - // [{ sorted, items }] indexed by depth #deps = [] #sorted = true - #minDepth = 0 - #length = 0 get length () { - return this.#length + return this.#deps.length } push (item) { - if (!this.#deps[item.depth]) { - this.#length++ - this.#deps[item.depth] = { sorted: true, items: [item] } - // no minDepth check needed, this branch is only reached when we are in - // the middle of a shallower depth and creating a new one - return - } - if (!this.#deps[item.depth].items.includes(item)) { - this.#length++ - this.#deps[item.depth].sorted = false - this.#deps[item.depth].items.push(item) - if (item.depth < this.#minDepth) { - this.#minDepth = item.depth - } + if (!this.#deps.includes(item)) { + this.#sorted = false + this.#deps.push(item) } } pop () { - let depth - while (!depth?.items.length) { - depth = this.#deps[this.#minDepth] - if (!depth?.items.length) { - this.#minDepth++ - } - } - if (!depth.sorted) { - depth.items.sort((a, b) => localeCompare(a.path, b.path)) - depth.sorted = true + if (!this.#sorted) { + this.#deps.sort((a, b) => (a.depth - b.depth) || localeCompare(a.path, b.path)) + this.#sorted = true } - this.#length-- - return depth.items.shift() + return this.#deps.shift() } }