From bf3678ca81204f8ea9c253cc35a96c6c7ce12b42 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Sat, 8 Oct 2022 20:06:43 +0700 Subject: New Spans methods --- crypto/src/util/Spans.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'crypto/src/util') 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 @@ -8,11 +8,35 @@ namespace Org.BouncyCastle.Utilities { internal static class Spans { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static void CopyFrom(this Span output, ReadOnlySpan input) + { + input[..output.Length].CopyTo(output); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static Span FromNullable(T[]? array) + { + return array == null ? Span.Empty : array.AsSpan(); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Span FromNullable(T[]? array, int start) { return array == null ? Span.Empty : array.AsSpan(start); } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static ReadOnlySpan FromNullableReadOnly(T[]? array) + { + return array == null ? Span.Empty : array.AsSpan(); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static ReadOnlySpan FromNullableReadOnly(T[]? array, int start) + { + return array == null ? Span.Empty : array.AsSpan(start); + } } } #endif -- cgit 1.4.1