提交 23b4735f 编写于 作者: C CyrusNajmabadi 提交者: Jason Malinowski

Don't allocate a iterator each time we compute hashcodes.

上级 67fe11ba
......@@ -19,7 +19,6 @@ private class GetHashCodeVisitor
private readonly bool _objectAndDynamicCompareEqually;
private readonly Func<int, IParameterSymbol, int> _parameterAggregator;
private readonly Func<int, ISymbol, int> _symbolAggregator;
private readonly Func<int, INamedTypeSymbol, int> _namedTypeAggregator;
public GetHashCodeVisitor(
SymbolEquivalenceComparer symbolEquivalenceComparer,
......@@ -31,7 +30,6 @@ private class GetHashCodeVisitor
_objectAndDynamicCompareEqually = objectAndDynamicCompareEqually;
_parameterAggregator = (acc, sym) => Hash.Combine(symbolEquivalenceComparer.ParameterEquivalenceComparer.GetHashCode(sym), acc);
_symbolAggregator = (acc, sym) => GetHashCode(sym, acc);
_namedTypeAggregator = CombineNamedTypeHashCode;
}
public int GetHashCode(ISymbol x, int currentHash)
......@@ -171,10 +169,25 @@ private int CombineHashCodes(IModuleSymbol x, int currentHash)
private int CombineHashCodes(INamedTypeSymbol x, int currentHash)
{
return Unwrap(x).Aggregate(currentHash, _namedTypeAggregator);
currentHash = CombineNamedTypeHashCode(x, currentHash);
var errorType = x as IErrorTypeSymbol;
if (errorType != null)
{
foreach (var candidate in errorType.CandidateSymbols)
{
var candidateNamedType = candidate as INamedTypeSymbol;
if (candidateNamedType != null)
{
currentHash = CombineNamedTypeHashCode(candidateNamedType, currentHash);
}
}
}
return currentHash;
}
private int CombineNamedTypeHashCode(int currentHash, INamedTypeSymbol x)
private int CombineNamedTypeHashCode(INamedTypeSymbol x, int currentHash)
{
// If we want object and dynamic to be the same, and this is 'object', then return
// the same hash we do for 'dynamic'.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册