From aff0d563260a2eb20f0724197d5f29691b359d99 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 7 Jun 2020 11:56:04 +0200 Subject: [PATCH 1/2] Remove an unnecessary `RefSetCache.prototype.has()` call from `GlobalImageCache.getData` We can simply attempt to get the data *directly*, and instead check the result, rather than first checking if it exists. --- src/core/image_utils.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/image_utils.js b/src/core/image_utils.js index ea1090dff..2fbb93eb0 100644 --- a/src/core/image_utils.js +++ b/src/core/image_utils.js @@ -107,11 +107,10 @@ class GlobalImageCache { } getData(ref, pageIndex) { - if (!this._refCache.has(ref)) { + const pageIndexSet = this._refCache.get(ref); + if (!pageIndexSet) { return null; } - const pageIndexSet = this._refCache.get(ref); - if (pageIndexSet.size < GlobalImageCache.NUM_PAGES_THRESHOLD) { return null; } From df7d8c74cac4ceae84dfeb0efffd7fb399fed6d7 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 7 Jun 2020 12:01:51 +0200 Subject: [PATCH 2/2] Extract the actual sending of image data from the `PartialEvaluator.buildPaintImageXObject` method After PRs 10727 and 11912, the code responsible for sending the decoded image data to the main-thread has now become a fair bit more involved the previously. To reduce the amount of duplication here, the actual code responsible for sending the data is thus extracted into a new helper method instead. --- src/core/evaluator.js | 58 +++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 7b101d30a..44c779265 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -439,6 +439,30 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { }); }, + _sendImgData(objId, imgData, cacheGlobally = false) { + const transfers = imgData ? [imgData.data.buffer] : null; + + if (this.parsingType3Font) { + return this.handler.sendWithPromise( + "commonobj", + [objId, "FontType3Res", imgData], + transfers + ); + } + if (cacheGlobally) { + return this.handler.send( + "commonobj", + [objId, "Image", imgData], + transfers + ); + } + return this.handler.send( + "obj", + [objId, this.pageIndex, "Image", imgData], + transfers + ); + }, + async buildPaintImageXObject({ resources, image, @@ -552,42 +576,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { .then(imageObj => { imgData = imageObj.createImageData(/* forceRGBA = */ false); - if (this.parsingType3Font) { - return this.handler.sendWithPromise( - "commonobj", - [objId, "FontType3Res", imgData], - [imgData.data.buffer] - ); - } else if (cacheGlobally) { - this.handler.send( - "commonobj", - [objId, "Image", imgData], - [imgData.data.buffer] - ); - return undefined; - } - this.handler.send( - "obj", - [objId, this.pageIndex, "Image", imgData], - [imgData.data.buffer] - ); - return undefined; + return this._sendImgData(objId, imgData, cacheGlobally); }) .catch(reason => { warn("Unable to decode image: " + reason); - if (this.parsingType3Font) { - return this.handler.sendWithPromise("commonobj", [ - objId, - "FontType3Res", - null, - ]); - } else if (cacheGlobally) { - this.handler.send("commonobj", [objId, "Image", null]); - return undefined; - } - this.handler.send("obj", [objId, this.pageIndex, "Image", null]); - return undefined; + return this._sendImgData(objId, /* imgData = */ null, cacheGlobally); }); if (this.parsingType3Font) {