From e18edf38db46d74f8b1d801ac20663ed4e98197a Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 24 Apr 2022 11:10:02 +0200 Subject: [PATCH] Add a helper function for incrementing the `count` of cached ImageMasks While working on PR 14825, I couldn't help noticing that the code to increment the `count` for cached ImageMasks was repeated multiple times. Hence it makes sense, as far as I'm concerned, to move this into a helper function instead. --- src/core/evaluator.js | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 64e41f76b..97c180499 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -170,6 +170,16 @@ function normalizeBlendMode(value, parsingArray = false) { return "source-over"; } +function incrementCachedImageMaskCount(data) { + if ( + data.fn === OPS.paintImageMaskXObject && + data.args[0] && + data.args[0].count > 0 + ) { + data.args[0].count++; + } +} + // Trying to minimize Date.now() usage and check every 100 time. class TimeSlotManager { static get TIME_SLOT_DURATION_MS() { @@ -1707,13 +1717,7 @@ class PartialEvaluator { localImage.optionalContent ); - if ( - localImage.fn === OPS.paintImageMaskXObject && - localImage.args[0] && - localImage.args[0].count > 0 - ) { - localImage.args[0].count++; - } + incrementCachedImageMaskCount(localImage); args = null; continue; } @@ -1735,13 +1739,7 @@ class PartialEvaluator { localImage.optionalContent ); - if ( - localImage.fn === OPS.paintImageMaskXObject && - localImage.args[0] && - localImage.args[0].count > 0 - ) { - localImage.args[0].count++; - } + incrementCachedImageMaskCount(localImage); resolveXObject(); return; } @@ -1867,13 +1865,7 @@ class PartialEvaluator { localImage.optionalContent ); - if ( - localImage.fn === OPS.paintImageMaskXObject && - localImage.args[0] && - localImage.args[0].count > 0 - ) { - localImage.args[0].count++; - } + incrementCachedImageMaskCount(localImage); args = null; continue; }