Skip to content

Commit 5af9301

Browse files
authored
Revert "Shorten UTD marker file (#9387)" except Microsoft.Common.CurrentVersion.targets (#9520)
#9387 introduced improved hashing for [`[MSBuild]::StableStringHash`](https://learn.microsoft.com/en-us/visualstudio/msbuild/property-functions?view=vs-2022#msbuild-stablestringhash), that however broke internal functionality relying on the hash to be stable between versions (despite documented otherwise). ### Changes Made * Reverted all the hashing changes * Kept the UTD marker change (fixing #9346) ### Note Longer term fix: #9519
1 parent 67d742f commit 5af9301

File tree

3 files changed

+36
-144
lines changed

3 files changed

+36
-144
lines changed

src/Build/Evaluation/IntrinsicFunctions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
using Microsoft.Build.Shared;
1515
using Microsoft.Build.Shared.FileSystem;
1616
using Microsoft.Build.Utilities;
17-
using Microsoft.NET.StringTools;
1817
using Microsoft.Win32;
1918

2019
// Needed for DoesTaskHostExistForParameters
@@ -399,11 +398,11 @@ internal static string ConvertFromBase64(string toDecode)
399398
}
400399

401400
/// <summary>
402-
/// Hash the string independent of bitness, target framework and default codepage of the environment.
401+
/// Hash the string independent of bitness and target framework.
403402
/// </summary>
404403
internal static int StableStringHash(string toHash)
405404
{
406-
return FowlerNollVo1aHash.ComputeHash32(toHash);
405+
return CommunicationsUtilities.GetHashCode(toHash);
407406
}
408407

409408
/// <summary>

src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
using Microsoft.Build.Framework;
1515
using Microsoft.Build.Framework.Profiler;
1616
using Microsoft.Build.Shared;
17-
using Microsoft.Build.Utilities;
18-
using Microsoft.NET.StringTools;
1917

2018
#nullable disable
2119

@@ -1261,9 +1259,9 @@ private void Write(IExtendedBuildEventArgs extendedData)
12611259

12621260
internal readonly struct HashKey : IEquatable<HashKey>
12631261
{
1264-
private readonly long value;
1262+
private readonly ulong value;
12651263

1266-
private HashKey(long i)
1264+
private HashKey(ulong i)
12671265
{
12681266
value = i;
12691267
}
@@ -1276,13 +1274,13 @@ public HashKey(string text)
12761274
}
12771275
else
12781276
{
1279-
value = FowlerNollVo1aHash.ComputeHash64Fast(text);
1277+
value = FnvHash64.GetHashCode(text);
12801278
}
12811279
}
12821280

12831281
public static HashKey Combine(HashKey left, HashKey right)
12841282
{
1285-
return new HashKey(FowlerNollVo1aHash.Combine64(left.value, right.value));
1283+
return new HashKey(FnvHash64.Combine(left.value, right.value));
12861284
}
12871285

12881286
public HashKey Add(HashKey other) => Combine(this, other);
@@ -1312,5 +1310,35 @@ public override string ToString()
13121310
return value.ToString();
13131311
}
13141312
}
1313+
1314+
internal static class FnvHash64
1315+
{
1316+
public const ulong Offset = 14695981039346656037;
1317+
public const ulong Prime = 1099511628211;
1318+
1319+
public static ulong GetHashCode(string text)
1320+
{
1321+
ulong hash = Offset;
1322+
1323+
unchecked
1324+
{
1325+
for (int i = 0; i < text.Length; i++)
1326+
{
1327+
char ch = text[i];
1328+
hash = (hash ^ ch) * Prime;
1329+
}
1330+
}
1331+
1332+
return hash;
1333+
}
1334+
1335+
public static ulong Combine(ulong left, ulong right)
1336+
{
1337+
unchecked
1338+
{
1339+
return (left ^ right) * Prime;
1340+
}
1341+
}
1342+
}
13151343
}
13161344
}

src/StringTools/FowlerNollVo1aHash.cs

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)