From 4c57ec4da7415200d6fd74c1d9c4f588f4307cdf Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 17 Nov 2024 15:31:42 +0100 Subject: [PATCH] Improve clean-up of `#_hcmCache`-data in `DOMFilterFactory.prototype.destroy` - Use optional chaining when clearing various data-structures, since that's slightly shorter. - Ensure that checking for the existence of `#_hcmCache`-data won't cause it to be initialized. (Note how `this.#hcmCache` is actually a getter.) - Actually reset the `#_hcmCache`-data when that's appropriate, e.g. when closing the PDF document. --- src/display/filter_factory.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/display/filter_factory.js b/src/display/filter_factory.js index 84260464e..6b844db35 100644 --- a/src/display/filter_factory.js +++ b/src/display/filter_factory.js @@ -423,17 +423,18 @@ class DOMFilterFactory extends BaseFilterFactory { } destroy(keepHCM = false) { - if (keepHCM && this.#hcmCache.size !== 0) { + if (keepHCM && this.#_hcmCache?.size) { return; } - if (this.#_defs) { - this.#_defs.parentNode.parentNode.remove(); - this.#_defs = null; - } - if (this.#_cache) { - this.#_cache.clear(); - this.#_cache = null; - } + this.#_defs?.parentNode.parentNode.remove(); + this.#_defs = null; + + this.#_cache?.clear(); + this.#_cache = null; + + this.#_hcmCache?.clear(); + this.#_hcmCache = null; + this.#id = 0; }