Skip to content

Commit 83ef5fe

Browse files
authored
Optimize some double lookups on Dictionary (#691)
+semver:patch
1 parent 5e03583 commit 83ef5fe

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/FluentNHibernate/Conventions/Inspections/InspectorModelMapper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace FluentNHibernate.Conventions.Inspections;
77

88
public class InspectorModelMapper<TInspector, TMapping>
99
{
10-
readonly IDictionary<string, string> mappings = new Dictionary<string, string>();
10+
readonly Dictionary<string, string> mappings = new();
1111

1212
public void Map(Expression<Func<TInspector, object>> inspectorProperty, Expression<Func<TMapping, object>> mappingProperty)
1313
{
@@ -26,8 +26,8 @@ void Map(Member inspectorProperty, Expression<Func<TMapping, object>> mappingPro
2626

2727
public string Get(Member property)
2828
{
29-
if (mappings.ContainsKey(property.Name))
30-
return mappings[property.Name];
29+
if (mappings.TryGetValue(property.Name, out var mapping))
30+
return mapping;
3131

3232
return property.Name;
3333
}

src/FluentNHibernate/Infrastructure/Container.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace FluentNHibernate.Infrastructure;
55

66
public class Container
77
{
8-
readonly IDictionary<Type, Func<Container, object>> registeredTypes = new Dictionary<Type, Func<Container, object>>();
8+
readonly Dictionary<Type, Func<Container, object>> registeredTypes = new();
99

1010
public void Register<T>(Func<Container, object> instantiateFunc)
1111
{
@@ -14,10 +14,8 @@ public void Register<T>(Func<Container, object> instantiateFunc)
1414

1515
public object Resolve(Type type)
1616
{
17-
if (!registeredTypes.ContainsKey(type))
17+
if (!registeredTypes.TryGetValue(type, out var instantiationFunc))
1818
throw new ResolveException(type);
19-
20-
var instantiationFunc = registeredTypes[type];
2119

2220
return instantiationFunc(this);
2321
}

0 commit comments

Comments
 (0)