Skip to content

Commit

Permalink
Mark hash as unchecked
Browse files Browse the repository at this point in the history
  • Loading branch information
slozier committed Aug 21, 2020
1 parent 76b74da commit fa4af2f
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions Src/Microsoft.Scripting.Metadata/MetadataName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit fa4af2f

Please sign in to comment.