Merge pull request #17166 from calixteman/improve_oc_parsing

Improve performance of optional content parsing
This commit is contained in:
calixteman 2023-10-25 18:28:38 +02:00 committed by GitHub
commit b31e77df17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -438,14 +438,14 @@ class Catalog {
return shadow(this, "optionalContentConfig", null); return shadow(this, "optionalContentConfig", null);
} }
const groups = []; const groups = [];
const groupRefs = []; const groupRefs = new RefSet();
// Ensure all the optional content groups are valid. // Ensure all the optional content groups are valid.
for (const groupRef of groupsData) { for (const groupRef of groupsData) {
if (!(groupRef instanceof Ref)) { if (!(groupRef instanceof Ref) || groupRefs.has(groupRef)) {
continue; continue;
} }
groupRefs.push(groupRef); groupRefs.put(groupRef);
const group = this.xref.fetchIfRef(groupRef); const group = this.xref.fetch(groupRef);
groups.push({ groups.push({
id: groupRef.toString(), id: groupRef.toString(),
name: name:
@ -477,7 +477,7 @@ class Catalog {
if (!(value instanceof Ref)) { if (!(value instanceof Ref)) {
continue; continue;
} }
if (contentGroupRefs.includes(value)) { if (contentGroupRefs.has(value)) {
onParsed.push(value.toString()); onParsed.push(value.toString());
} }
} }
@ -492,7 +492,7 @@ class Catalog {
const order = []; const order = [];
for (const value of refs) { for (const value of refs) {
if (value instanceof Ref && contentGroupRefs.includes(value)) { if (value instanceof Ref && contentGroupRefs.has(value)) {
parsedOrderRefs.put(value); // Handle "hidden" groups, see below. parsedOrderRefs.put(value); // Handle "hidden" groups, see below.
order.push(value.toString()); order.push(value.toString());