From 9cbcfc52009d047535ec78a6e9ca9646dbd950fc Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 17 Dec 2024 17:02:52 +1100 Subject: [PATCH] . --- src/Polyfill/Polyfill_Memory_EndsWith.cs | 17 ++++++++++++----- src/Polyfill/Polyfill_Memory_SpanSplit.cs | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Polyfill/Polyfill_Memory_EndsWith.cs b/src/Polyfill/Polyfill_Memory_EndsWith.cs index 24380870..f60be216 100644 --- a/src/Polyfill/Polyfill_Memory_EndsWith.cs +++ b/src/Polyfill/Polyfill_Memory_EndsWith.cs @@ -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 { @@ -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(this ReadOnlySpan target, T value) - where T : IEquatable? => - target.Length != 0 && (target[^1]?.Equals(value) ?? (object?)value is null); + where T : IEquatable? + { + if (target.Length == 0) + { + return false; + } + + var last = target[target.Length-1]; + return last?.Equals(value) ?? (object?)value is null; + } #endif diff --git a/src/Polyfill/Polyfill_Memory_SpanSplit.cs b/src/Polyfill/Polyfill_Memory_SpanSplit.cs index cee06e9b..baead155 100644 --- a/src/Polyfill/Polyfill_Memory_SpanSplit.cs +++ b/src/Polyfill/Polyfill_Memory_SpanSplit.cs @@ -1,7 +1,7 @@ // #pragma warning disable -#if FeatureMemory +#if FeatureMemory && FeatureValueTuple namespace Polyfills; using System;