Skip to content

Commit f43f4ee

Browse files
committed
replace concurrentdictionary with generic instance creation
replace instance lambda with static copied from JakeBayer#42
1 parent 4fb074a commit f43f4ee

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

FuzzySharp/PreProcess/StringPreprocessorFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static Func<string, string> GetPreprocessor(PreprocessMode mode)
2727
return mode switch
2828
{
2929
PreprocessMode.Full => Default,
30-
PreprocessMode.None => s => s,
30+
PreprocessMode.None => static s => s,
3131
_ => throw new InvalidOperationException($"Invalid string preprocessor mode: {mode}")
3232
};
3333
}
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
using System;
2-
using System.Collections.Concurrent;
1+
using System.Runtime.CompilerServices;
32
using FuzzySharp.SimilarityRatio.Scorer;
43

54
namespace FuzzySharp.SimilarityRatio
65
{
76
public static class ScorerCache
87
{
9-
private static readonly ConcurrentDictionary<Type, IRatioScorer> s_scorerCache = new ConcurrentDictionary<Type, IRatioScorer>();
10-
public static IRatioScorer Get<T>() where T : IRatioScorer, new()
8+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
9+
public static IRatioScorer Get<T>() where T : IRatioScorer, new() => GenericCache<T>.Instance;
10+
11+
private static class GenericCache<T>
12+
where T : IRatioScorer, new()
1113
{
12-
return s_scorerCache.GetOrAdd(typeof(T), new T());
14+
public static readonly T Instance = new T();
1315
}
1416
}
15-
}
17+
}

0 commit comments

Comments
 (0)