1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 10:28:48 +00:00

refactor: remove zombie Span.Replace

This commit is contained in:
Oliver Booth 2024-11-14 18:36:02 +00:00
parent 02ab7dce47
commit 51e7d00c48
Signed by: oliverbooth
GPG Key ID: 2A862C3F46178E8E

View File

@ -16,28 +16,6 @@ public static class SpanExtensions
return source; return source;
} }
#if !NET8_0_OR_GREATER
/// <summary>
/// Replaces all occurrences of a specified element in a span of elements with another specified element.
/// </summary>
/// <param name="haystack">The source span.</param>
/// <param name="needle">The element to replace.</param>
/// <param name="replacement">The replacement element.</param>
/// <typeparam name="T">The type of elements in <paramref name="haystack" />.</typeparam>
public static void Replace<T>(this Span<T> haystack, T needle, T replacement) where T : struct
{
var comparer = EqualityComparer<T>.Default;
for (var index = 0; index < haystack.Length; index++)
{
if (comparer.Equals(haystack[index], needle))
{
haystack[index] = replacement;
}
}
}
#endif
#if !NET9_0_OR_GREATER #if !NET9_0_OR_GREATER
/// <summary> /// <summary>
/// Splits a span of elements into sub-spans based on a delimiting element. /// Splits a span of elements into sub-spans based on a delimiting element.