From 59cd4568b29aba53a11f2240518d356db3042361 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 4 Aug 2026 11:46:47 +0200 Subject: [PATCH] Cache the entire scand regular expression, in `src/scripting_api/util.js` Rather than only caching a string and then re-creating the regular expression on every `Util.prototype._scand` invocation, the entire regular expression can be cached directly instead. --- src/scripting_api/util.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/scripting_api/util.js b/src/scripting_api/util.js index 7ee8dd618..a5d3d2ac8 100644 --- a/src/scripting_api/util.js +++ b/src/scripting_api/util.js @@ -602,7 +602,7 @@ class Util extends PDFObject { : pattern; }); - return [re, actions]; + return [new RegExp(`^${re}$`, "g"), actions]; } _scand(cFormat, cDate, strict = false) { @@ -622,12 +622,10 @@ class Util extends PDFObject { return this.scand("m/d/yy h:MM:ss tt", cDate); } - const [re, actions] = (this.#scandCache ??= new Map()).getOrInsertComputed( - cFormat, - this.#createScandDataBound - ); + const [regex, actions] = (this.#scandCache ??= + new Map()).getOrInsertComputed(cFormat, this.#createScandDataBound); - const matches = new RegExp(`^${re}$`, "g").exec(cDate); + const matches = regex.exec(cDate); if (!matches || matches.length !== actions.length + 1) { return strict ? null : this.#tryToGuessDate(cFormat, cDate); }