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

Cleanup redundant NeitherNull methods #65807

Merged
merged 1 commit into from
Dec 6, 2022
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 @@ -298,33 +298,6 @@ private int Compare(BaseTypeDeclarationSyntax x, BaseTypeDeclarationSyntax y)
return result;
}

private static bool NeitherNull(object x, object y, out int comparisonResult)
{
if (x == null && y == null)
{
comparisonResult = 0;
return false;
}
else if (x == null)
{
// x == null && y != null
comparisonResult = -1;
return false;
}
else if (y == null)
{
// x != null && y == null
comparisonResult = 1;
return false;
}
else
{
// x != null && y != null
comparisonResult = 0;
return true;
}
}

private static bool ContainsToken(SyntaxTokenList list, SyntaxKind kind)
=> list.Contains(token => token.Kind() == kind);

Expand Down Expand Up @@ -421,24 +394,16 @@ private static bool EqualAccessibility(SyntaxNode x, SyntaxTokenList xModifiers,

private static bool EqualIdentifierName(SyntaxToken x, SyntaxToken y, out int comparisonResult)
{
if (NeitherNull(x, y, out comparisonResult))
{
comparisonResult = string.Compare(x.ValueText, y.ValueText, StringComparison.OrdinalIgnoreCase);
}

comparisonResult = string.Compare(x.ValueText, y.ValueText, StringComparison.OrdinalIgnoreCase);
return comparisonResult == 0;
}

private static bool EqualOperatorPrecedence(SyntaxToken x, SyntaxToken y, out int comparisonResult)
{
if (NeitherNull(x, y, out comparisonResult))
{
s_operatorPrecedenceMap.TryGetValue(x.Kind(), out var xPrecedence);
s_operatorPrecedenceMap.TryGetValue(y.Kind(), out var yPrecedence);

comparisonResult = xPrecedence - yPrecedence;
}
s_operatorPrecedenceMap.TryGetValue(x.Kind(), out var xPrecedence);
s_operatorPrecedenceMap.TryGetValue(y.Kind(), out var yPrecedence);

comparisonResult = xPrecedence - yPrecedence;
return comparisonResult == 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,24 +388,18 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
End Function

Private Shared Function EqualIdentifierName(x As SyntaxToken, y As SyntaxToken, ByRef comparisonResult As Integer) As Boolean
If NeitherNull(x, y, comparisonResult) Then
Copy link
Member Author

Choose a reason for hiding this comment

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

NeitherNull isn't deleted in here because the arguments in the remaining usage is a reference type.

comparisonResult = CaseInsensitiveComparison.Compare(x.ValueText, y.ValueText)
End If

comparisonResult = CaseInsensitiveComparison.Compare(x.ValueText, y.ValueText)
Return comparisonResult = 0
End Function

Private Shared Function EqualOperatorPrecedence(x As SyntaxToken, y As SyntaxToken, ByRef comparisonResult As Integer) As Boolean
If NeitherNull(x, y, comparisonResult) Then
Dim xPrecedence = 0
Dim yPrecedence = 0
Dim xPrecedence = 0
Dim yPrecedence = 0

s_operatorPrecedenceMap.TryGetValue(x.Kind, xPrecedence)
s_operatorPrecedenceMap.TryGetValue(y.Kind, yPrecedence)

comparisonResult = If(xPrecedence = yPrecedence, 0, If(xPrecedence < yPrecedence, -1, 1))
End If
s_operatorPrecedenceMap.TryGetValue(x.Kind, xPrecedence)
s_operatorPrecedenceMap.TryGetValue(y.Kind, yPrecedence)

comparisonResult = If(xPrecedence = yPrecedence, 0, If(xPrecedence < yPrecedence, -1, 1))
Return comparisonResult = 0
End Function

Expand Down