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.
This commit is contained in:
saripovdenis 2026-05-06 09:51:57 +08:00
parent 6d5e8696c4
commit 473f9b4592

View File

@ -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;
}