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

Remove unnecessary null suppressions in calls to RuntimeHelpers.GetHashCode #66842

Merged
merged 1 commit into from
Feb 14, 2023
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 @@ -44,8 +44,7 @@ public override int GetHashCode()
case BoundTestDecisionDagNode n:
return Hash.Combine(n.Test.GetHashCode(), Hash.Combine(RuntimeHelpers.GetHashCode(n.WhenFalse), RuntimeHelpers.GetHashCode(n.WhenTrue)));
case BoundWhenDecisionDagNode n:
// See https://github.com/dotnet/runtime/pull/31819 for why ! is temporarily required below.
return Hash.Combine(RuntimeHelpers.GetHashCode(n.WhenExpression!), Hash.Combine(RuntimeHelpers.GetHashCode(n.WhenFalse!), RuntimeHelpers.GetHashCode(n.WhenTrue)));
return Hash.Combine(RuntimeHelpers.GetHashCode(n.WhenExpression), Hash.Combine(RuntimeHelpers.GetHashCode(n.WhenFalse), RuntimeHelpers.GetHashCode(n.WhenTrue)));
case BoundLeafDecisionDagNode n:
return RuntimeHelpers.GetHashCode(n.Label);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ private ReferenceEqualityComparer()

public static int GetHashCode(object? a)
{
// https://github.com/dotnet/roslyn/issues/41539
return RuntimeHelpers.GetHashCode(a!);
return RuntimeHelpers.GetHashCode(a);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public int GetHashCode(IReference? obj)
return objSymbol.GetHashCode();
}

return obj is object ? RuntimeHelpers.GetHashCode(obj) : 0;
return RuntimeHelpers.GetHashCode(obj);
}

public bool Equals(INamespace? x, INamespace? y)
Expand Down Expand Up @@ -89,7 +89,7 @@ public int GetHashCode(INamespace? obj)
return objSymbol.GetHashCode();
}

return obj is object ? RuntimeHelpers.GetHashCode(obj) : 0;
return RuntimeHelpers.GetHashCode(obj);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ public static GreenNode.NodeFlags GetDefaultNodeFlags()
private static int GetCacheHash(int kind, GreenNode.NodeFlags flags, GreenNode? child1)
{
int code = (int)(flags) ^ kind;
// the only child is never null
// https://github.com/dotnet/roslyn/issues/41539
code = Hash.Combine(System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(child1!), code);
code = Hash.Combine(System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(child1), code);

// ensure nonnegative hash
return code & Int32.MaxValue;
Expand Down