mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-06 22:37:23 +02:00
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.
This commit is contained in:
parent
f1f1782f38
commit
59cd4568b2
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user