API Optimierungen

This commit is contained in:
Moritz Utcke
2023-05-06 23:02:54 +04:00
parent bc3878e645
commit 9619bf29f3
14 changed files with 396 additions and 31 deletions

18
src/lib/Memoization.ts Normal file
View File

@@ -0,0 +1,18 @@
type MemoizedFunction<T> = (...args: any[]) => T;
export function memoize<T>(func: (...args: any[]) => T): MemoizedFunction<T> {
const cache = new Map<string, T>();
return (...args: any[]): T => {
const key = JSON.stringify(args);
if (cache.has(key)) {
return cache.get(key)!;
}
const result = func(...args);
cache.set(key, result);
return result;
};
}