Address review comments

This commit is contained in:
Tom Hvitved
2023-09-21 12:50:17 +02:00
parent 2343e5ecd8
commit 04c4e739ac
4 changed files with 42 additions and 62 deletions

View File

@@ -14,17 +14,14 @@ public class MemoizedFunc<T1, T2> where T1 : notnull
this.f = f;
}
public T2 this[T1 s]
public T2 Invoke(T1 s)
{
get
if (!cache.TryGetValue(s, out var t))
{
if (!cache.TryGetValue(s, out var t))
{
t = f(s);
cache[s] = t;
}
return t;
t = f(s);
cache[s] = t;
}
return t;
}
}
@@ -38,11 +35,5 @@ public class ConcurrentMemoizedFunc<T1, T2> where T1 : notnull
this.f = f;
}
public T2 this[T1 s]
{
get
{
return cache.GetOrAdd(s, f);
}
}
public T2 Invoke(T1 s) => cache.GetOrAdd(s, f);
}