Skip to content

Commit b62d412

Browse files
committed
Create the number tree for the ParentTree only one time
1 parent 0a2680b commit b62d412

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/core/struct_tree.js

Lines changed: 11 additions & 7 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) {
@@ -745,7 +751,7 @@ class StructTreePage {
745751
return null;
746752
}
747753

748-
const parentTree = this.rootDict.get("ParentTree");
754+
const { parentTree } = this.root;
749755
if (!parentTree) {
750756
return null;
751757
}
@@ -755,10 +761,9 @@ class StructTreePage {
755761
}
756762

757763
const map = new Map();
758-
const numberTree = new NumberTree(parentTree, this.xref);
759764

760765
for (const [elemId] of ids) {
761-
const obj = numberTree.getRaw(elemId);
766+
const obj = parentTree.getRaw(elemId);
762767
if (obj instanceof Ref) {
763768
map.set(elemId, obj);
764769
}
@@ -771,7 +776,7 @@ class StructTreePage {
771776
return;
772777
}
773778

774-
const parentTree = this.rootDict.get("ParentTree");
779+
const { parentTree } = this.root;
775780
if (!parentTree) {
776781
return;
777782
}
@@ -782,10 +787,9 @@ class StructTreePage {
782787
}
783788

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

787791
if (Number.isInteger(id)) {
788-
const parentArray = numberTree.get(id);
792+
const parentArray = parentTree.get(id);
789793
if (Array.isArray(parentArray)) {
790794
for (const ref of parentArray) {
791795
if (ref instanceof Ref) {
@@ -799,7 +803,7 @@ class StructTreePage {
799803
return;
800804
}
801805
for (const [elemId, type] of ids) {
802-
const obj = numberTree.get(elemId);
806+
const obj = parentTree.get(elemId);
803807
if (obj) {
804808
const elem = this.addNode(this.xref.fetchIfRef(obj), map);
805809
if (

0 commit comments

Comments
 (0)