diff --git a/packages/types/src/codec/Enum.ts b/packages/types/src/codec/Enum.ts index 5367cfa353..3ded1661d5 100644 --- a/packages/types/src/codec/Enum.ts +++ b/packages/types/src/codec/Enum.ts @@ -155,42 +155,6 @@ function decodeEnum (registry: Registry, def: TypesDef, value?: any, index?: num return decodeFromValue(registry, def, value); } -const camelCaseMap = new Map(); - -function memoizedStringCamelCase (value: string): string { - { - const camelCaseValue = camelCaseMap.get(value); - - if (camelCaseValue) { - return camelCaseValue; - } - } - - const camelCaseValue = stringCamelCase(value); - - camelCaseMap.set(value, camelCaseValue); - - return camelCaseValue; -} - -const propertySuffixMap = new Map(); - -function memoizedPropertySuffix (value: string): string { - { - const suffix = propertySuffixMap.get(value); - - if (suffix) { - return suffix; - } - } - - const suffix = stringUpperFirst(stringCamelCase(value.replace(' ', '_'))); - - propertySuffixMap.set(value, suffix); - - return suffix; -} - /** * @name Enum * @description @@ -242,7 +206,7 @@ export class Enum implements IEnum { for (let i = 0; i < keys.length; i++) { const key = keys[i]; - const name = memoizedPropertySuffix(key); + const name = stringUpperFirst(stringCamelCase(key.replace(' ', '_'))); const askey = `as${name}`; const iskey = `is${name}`; @@ -380,7 +344,7 @@ export class Enum implements IEnum { public toJSON (): AnyJson { return this.#isBasic ? this.type - : { [memoizedStringCamelCase(this.type)]: this.#raw.toJSON() }; + : { [stringCamelCase(this.type)]: this.#raw.toJSON() }; } /** diff --git a/packages/types/src/codec/Set.ts b/packages/types/src/codec/Set.ts index 67961667b5..d6ee093254 100644 --- a/packages/types/src/codec/Set.ts +++ b/packages/types/src/codec/Set.ts @@ -80,24 +80,6 @@ function decodeSet (setValues: SetValues, value: string[] | Set | Uint8A return decodeSetNumber(setValues, value); } -const iskeyMap = new Map(); - -function memoizedIskey (value: string): string { - { - const iskey = iskeyMap.get(value); - - if (iskey) { - return iskey; - } - } - - const iskey = `is${stringUpperFirst(stringCamelCase(value))}`; - - iskeyMap.set(value, iskey); - - return iskey; -} - /** * @name Set * @description @@ -131,7 +113,7 @@ export class CodecSet extends Set implements ISet { for (let i = 0; i < keys.length; i++) { const key = keys[i]; - defineProperty(this, memoizedIskey(key), () => this.strings.includes(key)); + defineProperty(this, `is${stringUpperFirst(stringCamelCase(key))}`, () => this.strings.includes(key)); } } };