[#40] Client: Add memory optimization for hash

Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
Pavel Gross 2025-03-11 22:56:28 +03:00
parent 32a7e64538
commit 809bd90352
17 changed files with 170 additions and 64 deletions

View file

@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Security.Cryptography;
using System.Threading;
using CommunityToolkit.HighPerformance;
@ -60,14 +61,30 @@ public static class Extentions
}
}
public static byte[] Sha512(this byte[] value)
public static byte[] Sha512(this ReadOnlyMemory<byte> value)
{
bool lockTaken = false;
try
{
_spinlockSha512.Enter(ref lockTaken);
return _sha512.ComputeHash(value);
return _sha512.ComputeHash(value.AsStream());
}
finally
{
if (lockTaken)
_spinlockSha512.Exit(false);
}
}
public static byte[] Sha512(this Stream stream)
{
bool lockTaken = false;
try
{
_spinlockSha512.Enter(ref lockTaken);
return _sha512.ComputeHash(stream);
}
finally
{