Skip to content

Commit 5515ad4

Browse files
committed
Utils: Improve ArrayEqual
1 parent 3a2d83e commit 5515ad4

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

‎NBitcoin/Utils.cs‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -471,24 +471,26 @@ internal static void SafeSet(ManualResetEvent ar)
471471
}
472472
catch { }
473473
}
474-
public static bool ArrayEqual(byte[] a, byte[] b)
474+
public static bool ArrayEqual(byte[]? a, byte[]? b)
475475
{
476476
if (a == null && b == null)
477477
return true;
478-
if (a == null)
478+
if (a == null || b == null)
479479
return false;
480-
if (b == null)
481-
return false;
482-
return ArrayEqual(a, 0, b, 0, Math.Max(a.Length, b.Length));
480+
481+
if (a.Length != b.Length)
482+
return a.Length == 0 && b.Length == 0;
483+
484+
return ArrayEqual(a, 0, b, 0, a.Length);
483485
}
484-
public static bool ArrayEqual(byte[] a, int startA, byte[] b, int startB, int length)
486+
487+
public static bool ArrayEqual(byte[]? a, int startA, byte[]? b, int startB, int length)
485488
{
486489
if (a == null && b == null)
487490
return true;
488-
if (a == null)
489-
return false;
490-
if (b == null)
491+
if (a == null || b == null)
491492
return false;
493+
492494
var alen = a.Length - startA;
493495
var blen = b.Length - startB;
494496

0 commit comments

Comments
 (0)