Skip to content

Commit

Permalink
Changed: Unroll threshold for lower string hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Mar 12, 2024
1 parent c7f9f88 commit 35373ea
Showing 1 changed file with 2 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,47 +386,8 @@ internal static unsafe UIntPtr UnstableHashNonVectorLower32(this ReadOnlySpan<ch
// be ok because we expect this to be very rare in practice.
const uint normalizeToLowercase = 0x0020_0020; // valid both for big-endian and for little-endian

// 32 byte
while (length >= (sizeof(uint) / sizeof(char)) * 8)
{
length -= (sizeof(uint) / sizeof(char)) * 8;

var p0 = ptr[0];
var p1 = ptr[1];
if (!AllCharsInUIntAreAscii(p0 | p1))
goto NotAscii;

hash1 = (hash1 ^ (p0 | normalizeToLowercase)) * prime;
hash2 = (hash2 ^ (p1 | normalizeToLowercase)) * prime;

p0 = ptr[2];
p1 = ptr[3];
if (!AllCharsInUIntAreAscii(p0 | p1))
goto NotAscii;

hash1 = (hash1 ^ (p0 | normalizeToLowercase)) * prime;
hash2 = (hash2 ^ (p1 | normalizeToLowercase)) * prime;

p0 = ptr[4];
p1 = ptr[5];
if (!AllCharsInUIntAreAscii(p0 | p1))
goto NotAscii;

hash1 = (hash1 ^ (p0 | normalizeToLowercase)) * prime;
hash2 = (hash2 ^ (p1 | normalizeToLowercase)) * prime;

p0 = ptr[6];
p1 = ptr[7];
if (!AllCharsInUIntAreAscii(p0 | p1))
goto NotAscii;

hash1 = (hash1 ^ (p0 | normalizeToLowercase)) * prime;
hash2 = (hash2 ^ (p1 | normalizeToLowercase)) * prime;
ptr += 8;
}

// 16 byte
if (length >= (sizeof(uint) / sizeof(char)) * 4)
while (length >= (sizeof(uint) / sizeof(char)) * 4)
{
length -= (sizeof(uint) / sizeof(char)) * 4;

Expand Down Expand Up @@ -506,39 +467,8 @@ internal static unsafe UIntPtr UnstableHashNonVectorLower64(this ReadOnlySpan<ch
// be ok because we expect this to be very rare in practice.
const ulong normalizeToLowercase = 0x0020_0020_0020_0020; // valid both for big-endian and for little-endian

// 64 byte
while (length >= (sizeof(ulong) / sizeof(char)) * 8)
{
length -= (sizeof(ulong) / sizeof(char)) * 8;

var p0 = ptr[0];
var p1 = ptr[1];
var p2 = ptr[2];
var p3 = ptr[3];
if (!AllCharsInULongAreAscii(p0 | p1 | p2 | p3))
goto NotAscii;

hash1 = (hash1 ^ (p0 | normalizeToLowercase)) * prime;
hash2 = (hash2 ^ (p1 | normalizeToLowercase)) * prime;
hash1 = (hash1 ^ (p2 | normalizeToLowercase)) * prime;
hash2 = (hash2 ^ (p3 | normalizeToLowercase)) * prime;

p0 = ptr[4];
p1 = ptr[5];
p2 = ptr[6];
p3 = ptr[7];
if (!AllCharsInULongAreAscii(p0 | p1 | p2 | p3))
goto NotAscii;

hash1 = (hash1 ^ (p0 | normalizeToLowercase)) * prime;
hash2 = (hash2 ^ (p1 | normalizeToLowercase)) * prime;
hash1 = (hash1 ^ (p2 | normalizeToLowercase)) * prime;
hash2 = (hash2 ^ (p3 | normalizeToLowercase)) * prime;
ptr += 8;
}

// 32 byte
if (length >= (sizeof(ulong) / sizeof(char)) * 4)
while (length >= (sizeof(ulong) / sizeof(char)) * 4)
{
length -= (sizeof(ulong) / sizeof(char)) * 4;

Expand Down

0 comments on commit 35373ea

Please sign in to comment.