From 23b4735fdde4ba68bcdb54ac11dcbfad0473a0a5 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Thu, 18 Aug 2016 17:20:44 -0400 Subject: [PATCH] Don't allocate a iterator each time we compute hashcodes. --- ...lEquivalenceComparer.GetHashCodeVisitor.cs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Workspaces/Core/Portable/Shared/Utilities/SymbolEquivalenceComparer.GetHashCodeVisitor.cs b/src/Workspaces/Core/Portable/Shared/Utilities/SymbolEquivalenceComparer.GetHashCodeVisitor.cs index 0965a1fb1d4..7a8ef16a756 100644 --- a/src/Workspaces/Core/Portable/Shared/Utilities/SymbolEquivalenceComparer.GetHashCodeVisitor.cs +++ b/src/Workspaces/Core/Portable/Shared/Utilities/SymbolEquivalenceComparer.GetHashCodeVisitor.cs @@ -19,7 +19,6 @@ private class GetHashCodeVisitor private readonly bool _objectAndDynamicCompareEqually; private readonly Func _parameterAggregator; private readonly Func _symbolAggregator; - private readonly Func _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'. -- GitLab