Skip to content

Commit 1bb4c6f

Browse files
authored
perf(library): avoid hash buffer copy
1 parent bb81128 commit 1bb4c6f

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,9 @@ public async Task<string> GetHashCodeAsync(CancellationToken cancellationToken =
577577
var hash = await SHA512.HashDataAsync(memoryStream, cancellationToken).ConfigureAwait(false);
578578
#else
579579
using HashAlgorithm sha = SHA512.Create();
580-
var hash = sha.ComputeHash(memoryStream.ToArray());
580+
var hash = memoryStream.TryGetBuffer(out ArraySegment<byte> buffer)
581+
? sha.ComputeHash(buffer.Array!, buffer.Offset, checked((int)memoryStream.Length))
582+
: sha.ComputeHash(memoryStream.ToArray());
581583
#endif
582584

583585
return ConvertByteArrayToString(hash ?? []);

0 commit comments

Comments
 (0)