From 473f9b459220e74990499ebd18d121a5917e3c67 Mon Sep 17 00:00:00 2001 From: saripovdenis Date: Wed, 6 May 2026 09:51:57 +0800 Subject: [PATCH] Avoid quadratic traversal in NameOrNumberTree.getAll Using Array.prototype.shift() to drain the traversal queue makes each visited node move the remaining queued entries. For large name/number trees this can make getAll() spend quadratic time in queue management. Iterate over the queue with for...of instead. Children pushed while iterating are still visited, and the queue no longer needs repeated front removals. --- src/core/name_number_tree.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/name_number_tree.js b/src/core/name_number_tree.js index 8cb825350..952acafe0 100644 --- a/src/core/name_number_tree.js +++ b/src/core/name_number_tree.js @@ -46,8 +46,8 @@ class NameOrNumberTree { processed.put(this.root); } const queue = [this.root]; - while (queue.length > 0) { - const obj = xref.fetchIfRef(queue.shift()); + for (const node of queue) { + const obj = xref.fetchIfRef(node); if (!(obj instanceof Dict)) { continue; }