Inline the data lookup in the Dict.getArray method

Similar to the `get`/`getAsync` methods, this should be a *tiny* bit more efficient which cannot hurt considering that `getArray` is now used a lot more than when initially added.
This commit is contained in:
Jonas Jenwald 2021-05-14 09:59:04 +02:00
parent e394da5861
commit 70113131de

View File

@ -118,16 +118,24 @@ class Dict {
// Same as get(), but dereferences all elements if the result is an Array. // Same as get(), but dereferences all elements if the result is an Array.
getArray(key1, key2, key3) { getArray(key1, key2, key3) {
let value = this.get(key1, key2, key3); let value = this._map[key1];
if (!Array.isArray(value) || !this.xref) { if (value === undefined && key2 !== undefined) {
return value; value = this._map[key2];
} if (value === undefined && key3 !== undefined) {
value = value.slice(); // Ensure that we don't modify the Dict data. value = this._map[key3];
for (let i = 0, ii = value.length; i < ii; i++) { }
if (!(value[i] instanceof Ref)) { }
continue; if (value instanceof Ref && this.xref) {
value = this.xref.fetch(value, this.suppressEncryption);
}
if (Array.isArray(value)) {
value = value.slice(); // Ensure that we don't modify the Dict data.
for (let i = 0, ii = value.length; i < ii; i++) {
if (value[i] instanceof Ref && this.xref) {
value[i] = this.xref.fetch(value[i], this.suppressEncryption);
}
} }
value[i] = this.xref.fetch(value[i], this.suppressEncryption);
} }
return value; return value;
} }