Skip to content

Commit 2201777

Browse files
authored
Merge pull request #20425 from calixteman/only_parese_parenttree_one_time
Create the number tree for the ParentTree only one time
2 parents 0a2680b + 04db385 commit 2201777

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/core/struct_tree.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class StructTreeRoot {
4242
this.roleMap = new Map();
4343
this.structParentIds = null;
4444
this.kidRefToPosition = undefined;
45+
this.parentTree = null;
4546
}
4647

4748
getKidPosition(kidRef) {
@@ -70,6 +71,11 @@ class StructTreeRoot {
7071

7172
init() {
7273
this.readRoleMap();
74+
const parentTree = this.dict.get("ParentTree");
75+
if (!parentTree) {
76+
return;
77+
}
78+
this.parentTree = new NumberTree(parentTree, this.xref);
7379
}
7480

7581
#addIdToPage(pageRef, id, type) {
@@ -771,7 +777,7 @@ class StructTreePage {
771777
return;
772778
}
773779

774-
const parentTree = this.rootDict.get("ParentTree");
780+
const { parentTree } = this.root;
775781
if (!parentTree) {
776782
return;
777783
}
@@ -782,10 +788,9 @@ class StructTreePage {
782788
}
783789

784790
const map = new Map();
785-
const numberTree = new NumberTree(parentTree, this.xref);
786791

787792
if (Number.isInteger(id)) {
788-
const parentArray = numberTree.get(id);
793+
const parentArray = parentTree.get(id);
789794
if (Array.isArray(parentArray)) {
790795
for (const ref of parentArray) {
791796
if (ref instanceof Ref) {
@@ -799,7 +804,7 @@ class StructTreePage {
799804
return;
800805
}
801806
for (const [elemId, type] of ids) {
802-
const obj = numberTree.get(elemId);
807+
const obj = parentTree.get(elemId);
803808
if (obj) {
804809
const elem = this.addNode(this.xref.fetchIfRef(obj), map);
805810
if (

0 commit comments

Comments
 (0)