Skip to content

Commit 8d1a69e

Browse files
committed
enhance Cache to allow specializing the key comparer
1 parent 516efa1 commit 8d1a69e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

OpenRA.FileFormats/Primitives/Cache.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@
1515
namespace OpenRA.FileFormats
1616
{
1717
public class Cache<T, U> : IEnumerable<KeyValuePair<T, U>>
18-
{
19-
Dictionary<T, U> hax = new Dictionary<T, U>();
18+
{
19+
Dictionary<T, U> hax;
2020
Func<T,U> loader;
2121

22-
public Cache(Func<T,U> loader)
22+
public Cache(Func<T,U> loader, IEqualityComparer<T> c)
2323
{
24+
hax = new Dictionary<T, U>(c);
2425
if (loader == null)
2526
throw new ArgumentNullException();
2627

2728
this.loader = loader;
28-
}
29+
}
30+
31+
public Cache(Func<T, U> loader)
32+
: this(loader, EqualityComparer<T>.Default) { }
2933

3034
public U this[T key]
3135
{

0 commit comments

Comments
 (0)