Skip to content

Commit

Permalink
use MemoryExtenions.SequenceEqual for better performance (neo-project…
Browse files Browse the repository at this point in the history
…#3578)

Co-authored-by: Christopher Schuchardt <cschuchardt88@gmail.com>
nan01ab and cschuchardt88 authored Nov 15, 2024
1 parent 8328928 commit 8d946b4
Showing 2 changed files with 3 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/Neo.Cryptography.BLS12_381/Fp.cs
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Neo.Extensions;
using System.Buffers.Binary;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
@@ -152,11 +153,7 @@ public bool TryWrite(Span<byte> buffer)

public override string ToString()
{
var output = string.Empty;
foreach (var b in ToArray())
output += b.ToString("x2");

return "0x" + output;
return "0x" + ToArray().ToHexString();
}

public bool LexicographicallyLargest()
3 changes: 1 addition & 2 deletions src/Neo.Extensions/ByteArrayEqualityComparer.cs
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@

using System;
using System.Collections.Generic;
using System.Linq;

namespace Neo.Extensions
{
@@ -24,7 +23,7 @@ public bool Equals(byte[]? x, byte[]? y)
if (ReferenceEquals(x, y)) return true;
if (x is null || y is null || x.Length != y.Length) return false;

return x.SequenceEqual(y);
return x.AsSpan().SequenceEqual(y.AsSpan());
}

public int GetHashCode(byte[] obj)

0 comments on commit 8d946b4

Please sign in to comment.