未验证 提交 f6ad71ab 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #42962 from sharwell/faster-suppressions

Faster suppressions
......@@ -69,15 +69,15 @@ public override string GetMessage(IFormatProvider formatProvider = null)
public override bool Equals(Diagnostic obj)
{
var other = obj as SuppressionDiagnostic;
if (other == null)
if (ReferenceEquals(this, obj))
{
return false;
return true;
}
if (ReferenceEquals(this, other))
var other = obj as SuppressionDiagnostic;
if (other == null)
{
return true;
return false;
}
return Equals(_originalDiagnostic, other._originalDiagnostic) &&
......
......@@ -87,15 +87,15 @@ public override IReadOnlyList<Location> AdditionalLocations
public override bool Equals(Diagnostic? obj)
{
var other = obj as DiagnosticWithProgrammaticSuppression;
if (other == null)
if (ReferenceEquals(this, obj))
{
return false;
return true;
}
if (ReferenceEquals(this, other))
var other = obj as DiagnosticWithProgrammaticSuppression;
if (other == null)
{
return true;
return false;
}
return Equals(_originalUnsuppressedDiagnostic, other._originalUnsuppressedDiagnostic) &&
......
......@@ -173,6 +173,11 @@ public sealed class DiagnosticDescriptor : IEquatable<DiagnosticDescriptor?>
public bool Equals(DiagnosticDescriptor? other)
{
if (ReferenceEquals(this, other))
{
return true;
}
return
other != null &&
this.Category == other.Category &&
......
......@@ -150,7 +150,7 @@ public override bool Equals(object? obj)
public override bool Equals(Diagnostic? obj)
{
if (this == obj)
if (ReferenceEquals(this, obj))
{
return true;
}
......
......@@ -146,6 +146,11 @@ public override IReadOnlyList<Location> AdditionalLocations
public override bool Equals(Diagnostic? obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}
var other = obj as SimpleDiagnostic;
if (other == null)
{
......
......@@ -3,14 +3,16 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Diagnostics
{
/// <summary>
/// Programmatic suppression of a <see cref="Diagnostic"/> by a <see cref="DiagnosticSuppressor"/>.
/// </summary>
public struct Suppression
public struct Suppression : IEquatable<Suppression>
{
private Suppression(SuppressionDescriptor descriptor, Diagnostic suppressedDiagnostic)
{
......@@ -48,5 +50,34 @@ public static Suppression Create(SuppressionDescriptor descriptor, Diagnostic su
/// Diagnostic suppressed by this suppression.
/// </summary>
public Diagnostic SuppressedDiagnostic { get; }
public static bool operator ==(Suppression left, Suppression right)
{
return left.Equals(right);
}
public static bool operator !=(Suppression left, Suppression right)
{
return !(left == right);
}
public override bool Equals(object obj)
{
return obj is Suppression suppression
&& Equals(suppression);
}
public bool Equals(Suppression other)
{
return EqualityComparer<SuppressionDescriptor>.Default.Equals(Descriptor, other.Descriptor)
&& EqualityComparer<Diagnostic>.Default.Equals(SuppressedDiagnostic, other.SuppressedDiagnostic);
}
public override int GetHashCode()
{
return Hash.Combine(
EqualityComparer<SuppressionDescriptor>.Default.GetHashCode(Descriptor),
EqualityComparer<Diagnostic>.Default.GetHashCode(SuppressedDiagnostic));
}
}
}
Microsoft.CodeAnalysis.CommandLineSourceFile.CommandLineSourceFile(string path, bool isScript, bool isInputRedirected) -> void
Microsoft.CodeAnalysis.CommandLineSourceFile.IsInputRedirected.get -> bool
Microsoft.CodeAnalysis.Diagnostics.Suppression.Equals(Microsoft.CodeAnalysis.Diagnostics.Suppression other) -> bool
Microsoft.CodeAnalysis.GeneratorAttribute
Microsoft.CodeAnalysis.GeneratorAttribute.GeneratorAttribute() -> void
Microsoft.CodeAnalysis.GeneratorDriver
......@@ -26,5 +27,9 @@ Microsoft.CodeAnalysis.SourceGeneratorContext.SyntaxReceiver.get -> Microsoft.Co
Microsoft.CodeAnalysis.SyntaxNode.FirstAncestorOrSelf<TNode, TArg>(System.Func<TNode, TArg, bool> predicate, TArg argument, bool ascendOutOfTrivia = true) -> TNode
Microsoft.CodeAnalysis.SyntaxReceiverCreator
override Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference.GetGenerators() -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.ISourceGenerator>
override Microsoft.CodeAnalysis.Diagnostics.Suppression.Equals(object obj) -> bool
override Microsoft.CodeAnalysis.Diagnostics.Suppression.GetHashCode() -> int
static Microsoft.CodeAnalysis.Diagnostics.Suppression.operator !=(Microsoft.CodeAnalysis.Diagnostics.Suppression left, Microsoft.CodeAnalysis.Diagnostics.Suppression right) -> bool
static Microsoft.CodeAnalysis.Diagnostics.Suppression.operator ==(Microsoft.CodeAnalysis.Diagnostics.Suppression left, Microsoft.CodeAnalysis.Diagnostics.Suppression right) -> bool
virtual Microsoft.CodeAnalysis.Diagnostics.AnalyzerReference.GetGenerators() -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.ISourceGenerator>
const Microsoft.CodeAnalysis.WellKnownDiagnosticTags.CustomObsolete = "CustomObsolete" -> string
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册