Skip to content

Commit 005de95

Browse files
committed
Optimize dictionary access
1 parent b9e35b3 commit 005de95

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/SourceGeneration.Reflection/SourceReflector.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace SourceGeneration.Reflection;
66

7+
#pragma warning disable IDE0305
8+
79
public static class SourceReflector
810
{
911
private static readonly Dictionary<Type, SourceTypeInfo> _types = [];
@@ -12,8 +14,12 @@ public static class SourceReflector
1214
[EditorBrowsable(EditorBrowsableState.Never)]
1315
public static void Add(SourceTypeInfo typeInfo)
1416
{
17+
#if NET5_0_OR_GREATER
18+
_types.TryAdd(typeInfo.Type, typeInfo);
19+
#else
1520
if (!_types.ContainsKey(typeInfo.Type))
1621
_types.Add(typeInfo.Type, typeInfo);
22+
#endif
1723
}
1824

1925
public static T CreateInstance<

0 commit comments

Comments
 (0)