diff --git a/src/impl/digits.js b/src/impl/digits.js index 6ac1bae05..c8c68af0e 100644 --- a/src/impl/digits.js +++ b/src/impl/digits.js @@ -70,6 +70,21 @@ export function parseDigits(str) { } } +// cache of {numberingSystem: {append: regex}} +let digitRegexCache = {}; +export function resetDigitRegexCache() { + digitRegexCache = {}; +} + export function digitRegex({ numberingSystem }, append = "") { - return new RegExp(`${numberingSystems[numberingSystem || "latn"]}${append}`); + const ns = numberingSystem || "latn"; + + if (!digitRegexCache[ns]) { + digitRegexCache[ns] = {}; + } + if (!digitRegexCache[ns][append]) { + digitRegexCache[ns][append] = new RegExp(`${numberingSystems[ns]}${append}`); + } + + return digitRegexCache[ns][append]; } diff --git a/src/settings.js b/src/settings.js index 462e71e61..f109708d1 100644 --- a/src/settings.js +++ b/src/settings.js @@ -4,6 +4,7 @@ import Locale from "./impl/locale.js"; import { normalizeZone } from "./impl/zoneUtil.js"; import { validateWeekSettings } from "./impl/util.js"; +import { resetDigitRegexCache } from "./impl/digits.js"; let now = () => Date.now(), defaultZone = "system", @@ -171,5 +172,6 @@ export default class Settings { static resetCaches() { Locale.resetCache(); IANAZone.resetCache(); + resetDigitRegexCache(); } }