added RcSpans util

This commit is contained in:
ikpil 2024-04-27 11:08:55 +09:00
parent 2ef6c0b27c
commit 3ae7582043
3 changed files with 23 additions and 13 deletions

View File

@ -12,15 +12,6 @@ namespace DotRecast.Core
Array.Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length); Array.Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Copy<T>(Span<T> sourceArray, int sourceIndex, Span<T> destinationArray, int destinationIndex, int length)
{
var src = sourceArray.Slice(sourceIndex, length);
var dst = destinationArray.Slice(destinationIndex);
src.CopyTo(dst);
}
// Type Safe Copy // Type Safe Copy
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Copy<T>(T[] sourceArray, T[] destinationArray, long length) public static void Copy<T>(T[] sourceArray, T[] destinationArray, long length)

View File

@ -0,0 +1,22 @@
using System;
using System.Runtime.CompilerServices;
namespace DotRecast.Core
{
public static class RcSpans
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Copy<T>(Span<T> source, Span<T> destination)
{
Copy(source, 0, destination, 0, source.Length);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Copy<T>(Span<T> source, int sourceIdx, Span<T> destination, int destinationIdx, int length)
{
var src = source.Slice(sourceIdx, length);
var dst = destination.Slice(destinationIdx);
src.CopyTo(dst);
}
}
}

View File

@ -134,9 +134,7 @@ public class RcArrayBenchmarkTests
var resultSpan = Bench($"Span<long[], {list[seq].src.Length}>", _ => var resultSpan = Bench($"Span<long[], {list[seq].src.Length}>", _ =>
{ {
var v = list[seq]; var v = list[seq];
Span<long> src = v.src; RcSpans.Copy<long>(v.src, 0, v.dest, 0, v.src.Length);
Span<long> dest = v.dest;
RcArrays.Copy(src, 0, dest, 0, src.Length);
}); });
@ -154,7 +152,6 @@ public class RcArrayBenchmarkTests
{ {
Console.WriteLine(""); Console.WriteLine("");
} }
} }
} }
} }