performance and usability improvements
This commit is contained in:
parent
a25396b6f2
commit
ab988898c0
18 changed files with 381 additions and 206 deletions
|
|
@ -11,3 +11,15 @@ export function compactTime(timeMs: number) {
|
|||
return `${timeMs} ms`;
|
||||
}
|
||||
|
||||
export function memoize<InType,OutType>(fn: (i: InType) => OutType) {
|
||||
const cache = new Map();
|
||||
return (i: InType) => {
|
||||
const found = cache.get(i);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
const result = fn(i);
|
||||
cache.set(i, result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue