|
|
@ -10,10 +10,32 @@ namespace ICSharpCode.SharpDevelop.Dom |
|
|
|
{ |
|
|
|
{ |
|
|
|
public class ParameterListComparer : IEqualityComparer<IMethod> |
|
|
|
public class ParameterListComparer : IEqualityComparer<IMethod> |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
Dictionary<IMethod, int> cachedHashes; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Gets/Sets whether to cache hashcodes. This can improve performance for
|
|
|
|
|
|
|
|
/// algorithms that repeatedly request the hash of a parameter list.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
|
|
/// This class is thread-safe only when not using cached hashes.
|
|
|
|
|
|
|
|
/// Also, cached hashes may cause a memory leak when the ParameterListComparer
|
|
|
|
|
|
|
|
/// instance is kept alive.
|
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public bool UseCachedHashes { |
|
|
|
|
|
|
|
get { |
|
|
|
|
|
|
|
return cachedHashes != null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
set { |
|
|
|
|
|
|
|
cachedHashes = value ? new Dictionary<IMethod, int>() : null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public bool Equals(IMethod x, IMethod y) |
|
|
|
public bool Equals(IMethod x, IMethod y) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (cachedHashes != null) { |
|
|
|
if (GetHashCode(x) != GetHashCode(y)) |
|
|
|
if (GetHashCode(x) != GetHashCode(y)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
var paramsX = x.Parameters; |
|
|
|
var paramsX = x.Parameters; |
|
|
|
var paramsY = y.Parameters; |
|
|
|
var paramsY = y.Parameters; |
|
|
|
if (paramsX.Count != paramsY.Count) |
|
|
|
if (paramsX.Count != paramsY.Count) |
|
|
@ -31,12 +53,10 @@ namespace ICSharpCode.SharpDevelop.Dom |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Dictionary<IMethod, int> cachedHashes = new Dictionary<IMethod, int>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int GetHashCode(IMethod obj) |
|
|
|
public int GetHashCode(IMethod obj) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int hashCode; |
|
|
|
int hashCode; |
|
|
|
if (cachedHashes.TryGetValue(obj, out hashCode)) |
|
|
|
if (cachedHashes != null && cachedHashes.TryGetValue(obj, out hashCode)) |
|
|
|
return hashCode; |
|
|
|
return hashCode; |
|
|
|
hashCode = obj.TypeParameters.Count; |
|
|
|
hashCode = obj.TypeParameters.Count; |
|
|
|
unchecked { |
|
|
|
unchecked { |
|
|
@ -49,6 +69,7 @@ namespace ICSharpCode.SharpDevelop.Dom |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (cachedHashes != null) |
|
|
|
cachedHashes[obj] = hashCode; |
|
|
|
cachedHashes[obj] = hashCode; |
|
|
|
return hashCode; |
|
|
|
return hashCode; |
|
|
|
} |
|
|
|
} |
|
|
|