From 70113131de87217eaf356ab5b005c64db6d02d0b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 14 May 2021 09:59:04 +0200 Subject: [PATCH] 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. --- src/core/primitives.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/core/primitives.js b/src/core/primitives.js index ca8e59bdb..c35dedef5 100644 --- a/src/core/primitives.js +++ b/src/core/primitives.js @@ -118,16 +118,24 @@ class Dict { // Same as get(), but dereferences all elements if the result is an Array. getArray(key1, key2, key3) { - let value = this.get(key1, key2, key3); - if (!Array.isArray(value) || !this.xref) { - return 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)) { - continue; + let value = this._map[key1]; + if (value === undefined && key2 !== undefined) { + value = this._map[key2]; + if (value === undefined && key3 !== undefined) { + value = this._map[key3]; + } + } + 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; }