Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid boxing when structs are used as collection keys. #69443

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal enum HighlightSpanKind
}

[DataContract]
internal readonly struct HighlightSpan
internal readonly record struct HighlightSpan
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Why is this one changing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ This type isn't used as a dictionary key, but rather as a dictionary value in a type that happens to create a set from the values.

{
[DataMember(Order = 0)]
public TextSpan TextSpan { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Diagnostics;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.FindSymbols
Expand Down Expand Up @@ -63,11 +62,11 @@ private string GetDebuggerDisplay()
=> Name + ", " + ParentIndex;
}

private readonly struct ParameterTypeInfo(string name, bool isComplex, bool isArray)
private readonly record struct ParameterTypeInfo(string name, bool isComplex, bool isArray)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Why is this one changing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ This type isn't used as a dictionary key, but rather as a dictionary value in a type that happens to create a set from the values.

{
/// <summary>
/// This is the type name of the parameter when <see cref="IsComplexType"/> is false.
/// For array types, this is just the elemtent type name.
/// For array types, this is just the element type name.
/// e.g. `int` for `int[][,]`
/// </summary>
public readonly string Name = name;
Expand Down Expand Up @@ -96,11 +95,11 @@ private readonly struct ParameterTypeInfo(string name, bool isComplex, bool isAr
public readonly bool IsComplexType = isComplex;
}

public readonly struct ExtensionMethodInfo(string fullyQualifiedContainerName, string name)
public readonly record struct ExtensionMethodInfo(string fullyQualifiedContainerName, string name)
{
/// <summary>
/// Name of the extension method.
/// This can be used to retrive corresponding symbols via <see cref="INamespaceOrTypeSymbol.GetMembers(string)"/>
/// This can be used to retrieve corresponding symbols via <see cref="INamespaceOrTypeSymbol.GetMembers(string)"/>
/// </summary>
public readonly string Name = name;

Expand Down