mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-01 20:07:22 +02:00
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:
parent
6d5e8696c4
commit
473f9b4592
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user