New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix long-standing String.GetHashCode x64 early halt bug #229

Closed
wants to merge 1 commit into
base: master
from
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+7 −5
Diff settings

Always

Just for now

@@ -857,11 +857,11 @@ unsafe public char[] ToCharArray(int startIndex, int length)
int hash1 = 5381;
#endif
int hash2 = hash1;
int len = this.Length;

#if WIN32
// 32 bit machines.
int* pint = (int *)src;
int len = this.Length;
while (len > 2)
{
hash1 = ((hash1 << 5) + hash1 + (hash1 >> 27)) ^ pint[0];
@@ -875,15 +875,17 @@ unsafe public char[] ToCharArray(int startIndex, int length)
hash1 = ((hash1 << 5) + hash1 + (hash1 >> 27)) ^ pint[0];
}
#else
int c;
int c;
char *s = src;
while ((c = s[0]) != 0) {
while (len > 0) {
c = s[0];
hash1 = ((hash1 << 5) + hash1) ^ c;
c = s[1];
if (c == 0)
if (len == 1)
break;
c = s[1];
hash2 = ((hash2 << 5) + hash2) ^ c;
s += 2;
len -= 2;
}
#endif
#if DEBUG
ProTip! Use n and p to navigate between commits in a pull request.