forked from mirror/DotRecast
added RcSpans util
This commit is contained in:
parent
2ef6c0b27c
commit
3ae7582043
|
@ -12,15 +12,6 @@ namespace DotRecast.Core
|
|||
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
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Copy<T>(T[] sourceArray, T[] destinationArray, long length)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -134,9 +134,7 @@ public class RcArrayBenchmarkTests
|
|||
var resultSpan = Bench($"Span<long[], {list[seq].src.Length}>", _ =>
|
||||
{
|
||||
var v = list[seq];
|
||||
Span<long> src = v.src;
|
||||
Span<long> dest = v.dest;
|
||||
RcArrays.Copy(src, 0, dest, 0, src.Length);
|
||||
RcSpans.Copy<long>(v.src, 0, v.dest, 0, v.src.Length);
|
||||
});
|
||||
|
||||
|
||||
|
@ -154,7 +152,6 @@ public class RcArrayBenchmarkTests
|
|||
{
|
||||
Console.WriteLine("");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue