Skip to content

Commit eec3d10

Browse files
committed
Refactoring ProxyCacheEntry constructor
1 parent 6fddfba commit eec3d10

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

src/NHibernate/Proxy/DynamicProxy/ProxyCacheEntry.cs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,30 @@ public class ProxyCacheEntry : IEquatable<ProxyCacheEntry>
1717

1818
public ProxyCacheEntry(System.Type baseType, System.Type[] interfaces)
1919
{
20-
if (baseType == null)
21-
throw new ArgumentNullException(nameof(baseType));
22-
BaseType = baseType;
23-
_uniqueInterfaces = new HashSet<System.Type>(interfaces ?? new System.Type[0]);
20+
BaseType = baseType ?? throw new ArgumentNullException(nameof(baseType));
2421

25-
if (_uniqueInterfaces.Count == 0)
26-
{
27-
_hashCode = baseType.GetHashCode();
28-
return;
29-
}
30-
31-
var allTypes = new List<System.Type>(_uniqueInterfaces) { baseType };
32-
_hashCode = 59;
33-
foreach (System.Type type in allTypes)
22+
var uniqueInterfaces = new HashSet<System.Type>();
23+
if (interfaces != null && interfaces.Length != 0)
24+
uniqueInterfaces.UnionWith(interfaces);
25+
_uniqueInterfaces = uniqueInterfaces;
26+
27+
_hashCode = 59 ^ baseType.GetHashCode();
28+
// This simple implementation is nonsensitive to list order. If changing it for a sensitive one,
29+
// take care of ordering the list.
30+
foreach (var type in _uniqueInterfaces)
3431
{
35-
// This simple implementation is nonsensitive to list order. If changing it for a sensitive one,
36-
// take care of ordering the list.
3732
_hashCode ^= type.GetHashCode();
3833
}
3934
}
4035

4136
public System.Type BaseType { get; }
42-
public IReadOnlyCollection<System.Type> Interfaces { get { return _uniqueInterfaces; } }
43-
44-
private HashSet<System.Type> _uniqueInterfaces;
37+
public IReadOnlyCollection<System.Type> Interfaces => _uniqueInterfaces;
38+
39+
private readonly HashSet<System.Type> _uniqueInterfaces;
4540

4641
public override bool Equals(object obj)
4742
{
48-
var that = obj as ProxyCacheEntry;
49-
return Equals(that);
43+
return Equals(obj as ProxyCacheEntry);
5044
}
5145

5246
public bool Equals(ProxyCacheEntry other)
@@ -64,4 +58,4 @@ public bool Equals(ProxyCacheEntry other)
6458

6559
public override int GetHashCode() => _hashCode;
6660
}
67-
}
61+
}

0 commit comments

Comments
 (0)