Skip to content

Commit b27ba05

Browse files
Copilotbaronfel
andcommitted
Fix HashLengthInBytes to use instance property instead of static access
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
1 parent 40ca057 commit b27ba05

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,11 @@ bool ShouldIncludeRuntimeAsset(ITaskItem item)
266266
// If file exists, check if content is different using streaming hash comparison
267267
if (File.Exists(depsFilePath))
268268
{
269+
// Get hash length from instance
270+
var hashLength = new XxHash64().HashLengthInBytes;
271+
269272
// Hash existing file content using streaming approach
270-
Span<byte> existingHashBuffer = stackalloc byte[XxHash64.HashLengthInBytes];
273+
Span<byte> existingHashBuffer = stackalloc byte[hashLength];
271274
var existingHasher = new XxHash64();
272275
using (var existingStream = File.OpenRead(depsFilePath))
273276
{
@@ -276,7 +279,7 @@ bool ShouldIncludeRuntimeAsset(ITaskItem item)
276279
existingHasher.GetCurrentHash(existingHashBuffer);
277280

278281
// Hash new content using streaming approach
279-
Span<byte> newHashBuffer = stackalloc byte[XxHash64.HashLengthInBytes];
282+
Span<byte> newHashBuffer = stackalloc byte[hashLength];
280283
var newHasher = new XxHash64();
281284
contentStream.Position = 0;
282285
newHasher.Append(contentStream);

src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,11 @@ private static void WriteToJsonFile(string fileName, object value)
408408
// If file exists, check if content is different using streaming hash comparison
409409
if (File.Exists(fileName))
410410
{
411+
// Get hash length from instance
412+
var hashLength = new XxHash64().HashLengthInBytes;
413+
411414
// Hash existing file content using streaming approach
412-
Span<byte> existingHashBuffer = stackalloc byte[XxHash64.HashLengthInBytes];
415+
Span<byte> existingHashBuffer = stackalloc byte[hashLength];
413416
var existingHasher = new XxHash64();
414417
using (var existingStream = File.OpenRead(fileName))
415418
{
@@ -418,7 +421,7 @@ private static void WriteToJsonFile(string fileName, object value)
418421
existingHasher.GetCurrentHash(existingHashBuffer);
419422

420423
// Hash new content using streaming approach
421-
Span<byte> newHashBuffer = stackalloc byte[XxHash64.HashLengthInBytes];
424+
Span<byte> newHashBuffer = stackalloc byte[hashLength];
422425
var newHasher = new XxHash64();
423426
contentStream.Position = 0;
424427
newHasher.Append(contentStream);

0 commit comments

Comments
 (0)