diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-10-08 20:06:43 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-10-08 20:06:43 +0700 |
commit | bf3678ca81204f8ea9c253cc35a96c6c7ce12b42 (patch) | |
tree | 9e134a828d6d21b00e38b425692a7c8df3106927 /crypto/src/util/Spans.cs | |
parent | Refactor TestSampler (diff) | |
download | BouncyCastle.NET-ed25519-bf3678ca81204f8ea9c253cc35a96c6c7ce12b42.tar.xz |
New Spans methods
Diffstat (limited to 'crypto/src/util/Spans.cs')
-rw-r--r-- | crypto/src/util/Spans.cs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/crypto/src/util/Spans.cs b/crypto/src/util/Spans.cs index 5e1b3737c..fa2b768d9 100644 --- a/crypto/src/util/Spans.cs +++ b/crypto/src/util/Spans.cs @@ -9,10 +9,34 @@ namespace Org.BouncyCastle.Utilities internal static class Spans { [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static void CopyFrom<T>(this Span<T> output, ReadOnlySpan<T> input) + { + input[..output.Length].CopyTo(output); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static Span<T> FromNullable<T>(T[]? array) + { + return array == null ? Span<T>.Empty : array.AsSpan(); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Span<T> FromNullable<T>(T[]? array, int start) { return array == null ? Span<T>.Empty : array.AsSpan(start); } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static ReadOnlySpan<T> FromNullableReadOnly<T>(T[]? array) + { + return array == null ? Span<T>.Empty : array.AsSpan(); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static ReadOnlySpan<T> FromNullableReadOnly<T>(T[]? array, int start) + { + return array == null ? Span<T>.Empty : array.AsSpan(start); + } } } #endif |