Remove memoized caches (Enum, Set) (#4178)

This commit is contained in:
Jaco
2021-11-06 12:01:40 +02:00
committed by GitHub
parent b648c4ba6c
commit b7c563391c
2 changed files with 3 additions and 57 deletions
+2 -38
View File
@@ -155,42 +155,6 @@ function decodeEnum (registry: Registry, def: TypesDef, value?: any, index?: num
return decodeFromValue(registry, def, value);
}
const camelCaseMap = new Map<string, string>();
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<string, string>();
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() };
}
/**
+1 -19
View File
@@ -80,24 +80,6 @@ function decodeSet (setValues: SetValues, value: string[] | Set<string> | Uint8A
return decodeSetNumber(setValues, value);
}
const iskeyMap = new Map<string, string>();
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<string> implements ISet<string> {
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));
}
}
};