Browse Source

Use a value tuple as the implicit-conversion cache key

TypePair existed only to key that cache, and its hand-written equality
delegated to the same IType comparison the tuple's default comparer performs.

Assisted-by: Claude:claude-opus-5[1m]:Claude Code
pull/4006/head
Siegfried Pammer 1 month ago
parent
commit
c155b7df3a
  1. 37
      ICSharpCode.Decompiler/CSharp/Resolver/CSharpConversions.cs

37
ICSharpCode.Decompiler/CSharp/Resolver/CSharpConversions.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -37,7 +37,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// </remarks>
public sealed class CSharpConversions
{
readonly ConcurrentDictionary<TypePair, Conversion> implicitConversionCache = new ConcurrentDictionary<TypePair, Conversion>();
readonly ConcurrentDictionary<(IType fromType, IType toType), Conversion> implicitConversionCache = new ConcurrentDictionary<(IType, IType), Conversion>();
readonly ICompilation compilation;
public CSharpConversions(ICompilation compilation)
@ -64,39 +64,6 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -64,39 +64,6 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return operators;
}
#region TypePair (for caching)
struct TypePair : IEquatable<TypePair>
{
public readonly IType FromType;
public readonly IType ToType;
public TypePair(IType fromType, IType toType)
{
Debug.Assert(fromType != null && toType != null);
this.FromType = fromType;
this.ToType = toType;
}
public override bool Equals(object obj)
{
return (obj is TypePair) && Equals((TypePair)obj);
}
public bool Equals(TypePair other)
{
return object.Equals(this.FromType, other.FromType) && object.Equals(this.ToType, other.ToType);
}
public override int GetHashCode()
{
unchecked
{
return 1000000007 * FromType.GetHashCode() + 1000000009 * ToType.GetHashCode();
}
}
}
#endregion
#region ImplicitConversion
private Conversion ImplicitConversion(ResolveResult resolveResult, IType toType, bool allowUserDefined, bool allowTuple)
{
@ -188,7 +155,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -188,7 +155,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
if (toType == null)
throw new ArgumentNullException(nameof(toType));
TypePair pair = new TypePair(fromType, toType);
var pair = (fromType, toType);
if (implicitConversionCache.TryGetValue(pair, out Conversion c))
return c;

Loading…
Cancel
Save