Merge pull request #20425 from calixteman/only_parese_parenttree_one_time

Create the number tree for the ParentTree only one time
This commit is contained in:
calixteman 2025-11-07 09:45:17 +01:00 committed by GitHub
commit 2201777d0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -42,6 +42,7 @@ class StructTreeRoot {
this.roleMap = new Map(); this.roleMap = new Map();
this.structParentIds = null; this.structParentIds = null;
this.kidRefToPosition = undefined; this.kidRefToPosition = undefined;
this.parentTree = null;
} }
getKidPosition(kidRef) { getKidPosition(kidRef) {
@ -70,6 +71,11 @@ class StructTreeRoot {
init() { init() {
this.readRoleMap(); this.readRoleMap();
const parentTree = this.dict.get("ParentTree");
if (!parentTree) {
return;
}
this.parentTree = new NumberTree(parentTree, this.xref);
} }
#addIdToPage(pageRef, id, type) { #addIdToPage(pageRef, id, type) {
@ -771,7 +777,7 @@ class StructTreePage {
return; return;
} }
const parentTree = this.rootDict.get("ParentTree"); const { parentTree } = this.root;
if (!parentTree) { if (!parentTree) {
return; return;
} }
@ -782,10 +788,9 @@ class StructTreePage {
} }
const map = new Map(); const map = new Map();
const numberTree = new NumberTree(parentTree, this.xref);
if (Number.isInteger(id)) { if (Number.isInteger(id)) {
const parentArray = numberTree.get(id); const parentArray = parentTree.get(id);
if (Array.isArray(parentArray)) { if (Array.isArray(parentArray)) {
for (const ref of parentArray) { for (const ref of parentArray) {
if (ref instanceof Ref) { if (ref instanceof Ref) {
@ -799,7 +804,7 @@ class StructTreePage {
return; return;
} }
for (const [elemId, type] of ids) { for (const [elemId, type] of ids) {
const obj = numberTree.get(elemId); const obj = parentTree.get(elemId);
if (obj) { if (obj) {
const elem = this.addNode(this.xref.fetchIfRef(obj), map); const elem = this.addNode(this.xref.fetchIfRef(obj), map);
if ( if (