diff --git a/src/StringTools/FowlerNollVo1aHash.cs b/src/StringTools/FowlerNollVo1aHash.cs index 7532a688669..29de98b5c59 100644 --- a/src/StringTools/FowlerNollVo1aHash.cs +++ b/src/StringTools/FowlerNollVo1aHash.cs @@ -33,7 +33,6 @@ public static int ComputeHash32(string text) { uint hash = fnvOffsetBasisA32Bit; -#if NET35 unchecked { for (int i = 0; i < text.Length; i++) @@ -48,20 +47,14 @@ public static int ComputeHash32(string text) hash *= fnvPrimeA32Bit; } } -#else - ReadOnlySpan span = MemoryMarshal.Cast(text.AsSpan()); - foreach (byte b in span) - { - hash = unchecked((hash ^ b) * fnvPrimeA32Bit); - } -#endif return unchecked((int)hash); } /// - /// Computes 64 bit Fowler/Noll/Vo-1a hash optimized for ASCII strings. - /// The hashing algorithm considers only the first 8 bits of each character. + /// Computes 64 bit Fowler/Noll/Vo-1a inspired hash of a string. + /// The hashing algorithm process the data by the whole 16bit chars, instead of by bytes. + /// this speeds up the hashing process almost by 2x, while not significantly increasing collisions rate. /// Analysis: https://github.com/KirillOsenkov/MSBuildStructuredLog/wiki/String-Hashing#faster-fnv-1a /// /// String to be hashed. @@ -92,7 +85,6 @@ public static long ComputeHash64(string text) { long hash = fnvOffsetBasisA64Bit; -#if NET35 unchecked { for (int i = 0; i < text.Length; i++) @@ -107,13 +99,6 @@ public static long ComputeHash64(string text) hash *= fnvPrimeA64Bit; } } -#else - ReadOnlySpan span = MemoryMarshal.Cast(text.AsSpan()); - foreach (byte b in span) - { - hash = unchecked((hash ^ b) * fnvPrimeA64Bit); - } -#endif return hash; }