aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-21 22:49:54 -0500
committerGitHub <noreply@github.com>2021-01-21 22:49:54 -0500
commitcf57c4e38d619d979ca39328bd9ec4821f284816 (patch)
tree0bd80612cc5200218f76ae51ab4025c33a7c26a6 /ext/bg
parent0bc5a4a971126adca1787d90db36b13716638290 (diff)
Simplify CacheMap (#1287)
* Simplify CacheMap, removing support for array path keys * Update keys * Update JsonSchemaValidator * Update AudioSystem
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/json-schema.js10
1 files changed, 7 insertions, 3 deletions
diff --git a/ext/bg/js/json-schema.js b/ext/bg/js/json-schema.js
index 85ced354..7b6b9c53 100644
--- a/ext/bg/js/json-schema.js
+++ b/ext/bg/js/json-schema.js
@@ -125,7 +125,7 @@ class JsonSchemaProxyHandler {
class JsonSchemaValidator {
constructor() {
- this._regexCache = new CacheMap(100, ([pattern, flags]) => new RegExp(pattern, flags));
+ this._regexCache = new CacheMap(100);
}
createProxy(target, schema) {
@@ -705,8 +705,12 @@ class JsonSchemaValidator {
}
_getRegex(pattern, flags) {
- const regex = this._regexCache.getOrCreate([pattern, flags]);
- regex.lastIndex = 0;
+ const key = `${flags}:${pattern}`;
+ let regex = this._regexCache.get(key);
+ if (typeof regex === 'undefined') {
+ regex = new RegExp(pattern, flags);
+ this._regexCache.set(key, regex);
+ }
return regex;
}
}