Skip to content

Commit fe3ae67

Browse files
committed
Tweak comment
1 parent 8ea4ecc commit fe3ae67

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/libraries/System.Private.CoreLib/src/System/SearchValues/IndexOfAnyAsciiSearcher.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,16 @@ public static void ComputeUniqueLowNibbleState<T>(ReadOnlySpan<T> values, out As
152152
valuesByLowNibble.SetElementUnsafe(value & 0xF, value);
153153
}
154154

155+
// Elements of 'valuesByLowNibble' where no value had that low nibble will be left uninitialized at 0.
156+
// For most, that is okay, as only the zero character in the input could ever match against them,
157+
// but where such input characters will always be mapped to the 0th element of 'valuesByLowNibble'.
158+
//
159+
// That does mean we could still see false positivies if none of the values had a low nibble of zero.
160+
// To avoid that, we can replace the 0th element with any other byte that has a non-zero low nibble.
161+
// The zero character will no longer match, and the new value we pick won't match either as
162+
// it will be mapped to a different element in 'valuesByLowNibble' given its non-zero low nibble.
155163
if (valuesByLowNibble.GetElement(0) == 0 && !lookup.Contains(0))
156164
{
157-
// Avoid false positives for the zero character if no other character has a low nibble of zero.
158-
// We can replace it with any other byte that has a non-zero low nibble.
159165
valuesByLowNibble.SetElementUnsafe(0, (byte)1);
160166
}
161167

0 commit comments

Comments
 (0)