Change the Catalog.openAction getter back to using an Object internally (PR 12543 follow-up)

Given that the `Map`-pattern apparently has undesirable performance characteristics, change this getter back to using an Object instead and check its size before returning it.
This commit is contained in:
Jonas Jenwald 2020-10-30 13:27:05 +01:00
parent a1e5581a0b
commit fdb6520012

View File

@ -25,7 +25,7 @@ import {
isBool, isBool,
isNum, isNum,
isString, isString,
objectFromEntries, objectSize,
PermissionFlag, PermissionFlag,
shadow, shadow,
stringToPDFString, stringToPDFString,
@ -787,7 +787,7 @@ class Catalog {
*/ */
get openAction() { get openAction() {
const obj = this._catDict.get("OpenAction"); const obj = this._catDict.get("OpenAction");
const openActionMap = new Map(); const openAction = Object.create(null);
if (isDict(obj)) { if (isDict(obj)) {
// Convert the OpenAction dictionary into a format that works with // Convert the OpenAction dictionary into a format that works with
@ -799,17 +799,17 @@ class Catalog {
Catalog.parseDestDictionary({ destDict, resultObj }); Catalog.parseDestDictionary({ destDict, resultObj });
if (Array.isArray(resultObj.dest)) { if (Array.isArray(resultObj.dest)) {
openActionMap.set("dest", resultObj.dest); openAction.dest = resultObj.dest;
} else if (resultObj.action) { } else if (resultObj.action) {
openActionMap.set("action", resultObj.action); openAction.action = resultObj.action;
} }
} else if (Array.isArray(obj)) { } else if (Array.isArray(obj)) {
openActionMap.set("dest", obj); openAction.dest = obj;
} }
return shadow( return shadow(
this, this,
"openAction", "openAction",
openActionMap.size > 0 ? objectFromEntries(openActionMap) : null objectSize(openAction) > 0 ? openAction : null
); );
} }