From fa4af2fa501ac964687448b1d3904bf7f736ec64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Fri, 21 Aug 2020 13:03:43 -0400 Subject: [PATCH] Mark hash as unchecked --- .../MetadataName.cs | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/Src/Microsoft.Scripting.Metadata/MetadataName.cs b/Src/Microsoft.Scripting.Metadata/MetadataName.cs index ea2f12c0..64551cf6 100644 --- a/Src/Microsoft.Scripting.Metadata/MetadataName.cs +++ b/Src/Microsoft.Scripting.Metadata/MetadataName.cs @@ -230,20 +230,22 @@ internal static int GetByteHashCode(byte* bytes) { int hash1 = 5381; int hash2 = hash1; - if (bytes != null) { - int c; - byte* s = bytes; - while ((c = s[0]) != 0) { - hash1 = ((hash1 << 5) + hash1) ^ c; - c = s[1]; - if (c == 0) { - break; + unchecked { + if (bytes != null) { + int c; + byte* s = bytes; + while ((c = s[0]) != 0) { + hash1 = ((hash1 << 5) + hash1) ^ c; + c = s[1]; + if (c == 0) { + break; + } + hash2 = ((hash2 << 5) + hash2) ^ c; + s += 2; } - hash2 = ((hash2 << 5) + hash2) ^ c; - s += 2; } + return hash1 + (hash2 * 1566083941); } - return hash1 + (hash2 * 1566083941); } internal static int GetByteHashCode(byte* bytes, int count) { @@ -252,19 +254,21 @@ internal static int GetByteHashCode(byte* bytes, int count) { int hash1 = 5381; int hash2 = hash1; - if (bytes != null) { - byte* last = bytes + count - 1; - byte* s = bytes; - while (s < last) { - hash1 = ((hash1 << 5) + hash1) ^ (int)s[0]; - hash2 = ((hash2 << 5) + hash2) ^ (int)s[1]; - s += 2; - } - if (s < bytes + count) { - hash1 = ((hash1 << 5) + hash1) ^ (int)s[0]; + unchecked { + if (bytes != null) { + byte* last = bytes + count - 1; + byte* s = bytes; + while (s < last) { + hash1 = ((hash1 << 5) + hash1) ^ (int)s[0]; + hash2 = ((hash2 << 5) + hash2) ^ (int)s[1]; + s += 2; + } + if (s < bytes + count) { + hash1 = ((hash1 << 5) + hash1) ^ (int)s[0]; + } } + return hash1 + (hash2 * 1566083941); } - return hash1 + (hash2 * 1566083941); } internal static bool Equals(byte* p, byte* q) {