Skip to content

Commit bc83100

Browse files
authored
Manually optimize a rem 64 instruction to avoid regression on runtimes which do not currently optimize it (#96203)
1 parent 1e8f0b3 commit bc83100

8 files changed

+8
-8
lines changed

src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenDictionary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private static FrozenDictionary<TKey, TValue> CreateFromDictionary<TKey, TValue>
166166
{
167167
if (key.Length < minLength) minLength = key.Length;
168168
if (key.Length > maxLength) maxLength = key.Length;
169-
lengthFilter |= (1UL << (key.Length % 64));
169+
lengthFilter |= (1UL << (key.Length & 0x3F));
170170
}
171171
Debug.Assert(minLength >= 0 && maxLength >= minLength);
172172

src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenSet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private static FrozenSet<T> CreateFromSet<T>(HashSet<T> source)
114114
{
115115
if (s.Length < minLength) minLength = s.Length;
116116
if (s.Length > maxLength) maxLength = s.Length;
117-
lengthFilter |= (1UL << (s.Length % 64));
117+
lengthFilter |= (1UL << (s.Length & 0x3F));
118118
}
119119
Debug.Assert(minLength >= 0 && maxLength >= minLength);
120120

src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_Full.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ internal OrdinalStringFrozenDictionary_Full(
2828

2929
private protected override bool Equals(string? x, string? y) => string.Equals(x, y);
3030
private protected override int GetHashCode(string s) => Hashing.GetHashCodeOrdinal(s.AsSpan());
31-
private protected override bool CheckLengthQuick(string key) => (_lengthFilter & (1UL << (key.Length % 64))) > 0;
31+
private protected override bool CheckLengthQuick(string key) => (_lengthFilter & (1UL << (key.Length & 0x3F))) > 0;
3232
}
3333
}

src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_FullCaseInsensitive.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ internal OrdinalStringFrozenDictionary_FullCaseInsensitive(
2828

2929
private protected override bool Equals(string? x, string? y) => StringComparer.OrdinalIgnoreCase.Equals(x, y);
3030
private protected override int GetHashCode(string s) => Hashing.GetHashCodeOrdinalIgnoreCase(s.AsSpan());
31-
private protected override bool CheckLengthQuick(string key) => (_lengthFilter & (1UL << (key.Length % 64))) > 0;
31+
private protected override bool CheckLengthQuick(string key) => (_lengthFilter & (1UL << (key.Length & 0x3F))) > 0;
3232
}
3333
}

src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_FullCaseInsensitiveAscii.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ internal OrdinalStringFrozenDictionary_FullCaseInsensitiveAscii(
2828

2929
private protected override bool Equals(string? x, string? y) => StringComparer.OrdinalIgnoreCase.Equals(x, y);
3030
private protected override int GetHashCode(string s) => Hashing.GetHashCodeOrdinalIgnoreCaseAscii(s.AsSpan());
31-
private protected override bool CheckLengthQuick(string key) => (_lengthFilter & (1UL << (key.Length % 64))) > 0;
31+
private protected override bool CheckLengthQuick(string key) => (_lengthFilter & (1UL << (key.Length & 0x3F))) > 0;
3232
}
3333
}

src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenSet_Full.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ internal OrdinalStringFrozenSet_Full(
2727

2828
private protected override bool Equals(string? x, string? y) => string.Equals(x, y);
2929
private protected override int GetHashCode(string s) => Hashing.GetHashCodeOrdinal(s.AsSpan());
30-
private protected override bool CheckLengthQuick(string key) => (_lengthFilter & (1UL << (key.Length % 64))) > 0;
30+
private protected override bool CheckLengthQuick(string key) => (_lengthFilter & (1UL << (key.Length & 0x3F))) > 0;
3131
}
3232
}

src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenSet_FullCaseInsensitive.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ internal OrdinalStringFrozenSet_FullCaseInsensitive(
2727

2828
private protected override bool Equals(string? x, string? y) => StringComparer.OrdinalIgnoreCase.Equals(x, y);
2929
private protected override int GetHashCode(string s) => Hashing.GetHashCodeOrdinalIgnoreCase(s.AsSpan());
30-
private protected override bool CheckLengthQuick(string key) => (_lengthFilter & (1UL << (key.Length % 64))) > 0;
30+
private protected override bool CheckLengthQuick(string key) => (_lengthFilter & (1UL << (key.Length & 0x3F))) > 0;
3131
}
3232
}

src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenSet_FullCaseInsensitiveAscii.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ internal OrdinalStringFrozenSet_FullCaseInsensitiveAscii(
2727

2828
private protected override bool Equals(string? x, string? y) => StringComparer.OrdinalIgnoreCase.Equals(x, y);
2929
private protected override int GetHashCode(string s) => Hashing.GetHashCodeOrdinalIgnoreCaseAscii(s.AsSpan());
30-
private protected override bool CheckLengthQuick(string key) => (_lengthFilter & (1UL << (key.Length % 64))) > 0;
30+
private protected override bool CheckLengthQuick(string key) => (_lengthFilter & (1UL << (key.Length & 0x3F))) > 0;
3131
}
3232
}

0 commit comments

Comments
 (0)