Skip to content

Commit

Permalink
Nullable improvements for `Microsoft.Extensions.Primitives.StringSegm…
Browse files Browse the repository at this point in the history
…ent` №2 (#58308)

* Remove attributes on Equals since `true` no longer means `text` is not `null`.
  • Loading branch information
maxkoshevoi authored Aug 30, 2021
1 parent 7ec2bb0 commit a501884
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public partial interface IChangeToken
public static bool Equals(Microsoft.Extensions.Primitives.StringSegment a, Microsoft.Extensions.Primitives.StringSegment b, System.StringComparison comparisonType) { throw null; }
public bool Equals(Microsoft.Extensions.Primitives.StringSegment other, System.StringComparison comparisonType) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; }
public bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] string? text) { throw null; }
public bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] string? text, System.StringComparison comparisonType) { throw null; }
public bool Equals(string? text) { throw null; }
public bool Equals(string? text, System.StringComparison comparisonType) { throw null; }
public override int GetHashCode() { throw null; }
public int IndexOf(char c) { throw null; }
public int IndexOf(char c, int start) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public bool Equals(StringSegment other, StringComparison comparisonType)
/// </summary>
/// <param name="text">The <see cref="string"/> to compare with the current <see cref="StringSegment"/>.</param>
/// <returns><see langword="true" /> if the specified <see cref="string"/> is equal to the current <see cref="StringSegment"/>; otherwise, <see langword="false" />.</returns>
public bool Equals([NotNullWhen(true)] string? text) => Equals(text, StringComparison.Ordinal);
public bool Equals(string? text) => Equals(text, StringComparison.Ordinal);

/// <summary>
/// Checks if the specified <see cref="string"/> is equal to the current <see cref="StringSegment"/>.
Expand All @@ -250,12 +250,12 @@ public bool Equals(StringSegment other, StringComparison comparisonType)
/// <param name="comparisonType">One of the enumeration values that specifies the rules to use in the comparison.</param>
/// <returns><see langword="true" /> if the specified <see cref="string"/> is equal to the current <see cref="StringSegment"/>; otherwise, <see langword="false" />.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals([NotNullWhen(true)] string? text, StringComparison comparisonType)
public bool Equals(string? text, StringComparison comparisonType)
{
if (!HasValue || text == null)
{
CheckStringComparison(comparisonType); // must arg check before returning
return text == Buffer; // return true if both are null
return text == Buffer; // only return true if both are null
}

return AsSpan().Equals(text.AsSpan(), comparisonType);
Expand Down

0 comments on commit a501884

Please sign in to comment.