From 46504f16810e71e6291a2562148ef6d38a9e49da Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Sun, 2 Oct 2022 01:11:53 +0700 Subject: Generic ReverseInPlace method --- crypto/src/util/Arrays.cs | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) (limited to 'crypto/src') diff --git a/crypto/src/util/Arrays.cs b/crypto/src/util/Arrays.cs index 25114aca3..c2ba9c3e1 100644 --- a/crypto/src/util/Arrays.cs +++ b/crypto/src/util/Arrays.cs @@ -901,36 +901,13 @@ namespace Org.BouncyCastle.Utilities return result; } - public static byte[] ReverseInPlace(byte[] a) + public static T[] ReverseInPlace(T[] array) { - if (null == a) - return null; - - int p1 = 0, p2 = a.Length - 1; - while (p1 < p2) - { - byte t1 = a[p1], t2 = a[p2]; - a[p1++] = t2; - a[p2--] = t1; - } - - return a; - } - - public static int[] ReverseInPlace(int[] a) - { - if (null == a) + if (null == array) return null; - int p1 = 0, p2 = a.Length - 1; - while (p1 < p2) - { - int t1 = a[p1], t2 = a[p2]; - a[p1++] = t2; - a[p2--] = t1; - } - - return a; + Array.Reverse(array); + return array; } public static void Clear(byte[] data) -- cgit 1.5.1