Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Dec 17, 2024
1 parent fb31207 commit 9cbcfc5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/Polyfill/Polyfill_Memory_EndsWith.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

#if FeatureMemory

using System.ComponentModel;
using System.Runtime.CompilerServices;

#pragma warning disable

namespace Polyfills;

using System;
using System.Text;
using System.ComponentModel;
using System.Runtime.CompilerServices;

static partial class Polyfill
{
Expand All @@ -25,8 +24,16 @@ static partial class Polyfill
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.endswith#system-memoryextensions-endswith-1(system-readonlyspan((-0))-0)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool EndsWith<T>(this ReadOnlySpan<T> target, T value)
where T : IEquatable<T>? =>
target.Length != 0 && (target[^1]?.Equals(value) ?? (object?)value is null);
where T : IEquatable<T>?
{
if (target.Length == 0)
{
return false;
}

var last = target[target.Length-1];
return last?.Equals(value) ?? (object?)value is null;
}

#endif

Expand Down
2 changes: 1 addition & 1 deletion src/Polyfill/Polyfill_Memory_SpanSplit.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// <auto-generated />
#pragma warning disable

#if FeatureMemory
#if FeatureMemory && FeatureValueTuple

namespace Polyfills;
using System;
Expand Down

0 comments on commit 9cbcfc5

Please sign in to comment.