Skip to content

Commit

Permalink
Use uint.TrailingZeroCount
Browse files Browse the repository at this point in the history
  • Loading branch information
xtqqczze committed Jun 20, 2023
1 parent 3989e4d commit 887ccac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ ref Unsafe.Add(ref valueRef, 1), valueTailLength))
// Do a full IgnoreCase equality comparison. SpanHelpers.IndexOf skips comparing the two characters in some cases,
// but we don't actually know that the two characters are equal, since we compared with | 0x20. So we just compare
// the full string always.
nint charPos = (nint)((uint)BitOperations.TrailingZeroCount(mask) / sizeof(ushort));
nint charPos = (nint)(uint.TrailingZeroCount(mask) / sizeof(ushort));
if (EqualsIgnoreCase(ref Unsafe.Add(ref searchSpace, offset + charPos), ref valueRef, value.Length))
{
// Match! Return the index.
Expand Down Expand Up @@ -528,7 +528,7 @@ ref Unsafe.Add(ref valueRef, 1), valueTailLength))
// Do a full IgnoreCase equality comparison. SpanHelpers.IndexOf skips comparing the two characters in some cases,
// but we don't actually know that the two characters are equal, since we compared with | 0x20. So we just compare
// the full string always.
nint charPos = (nint)((uint)BitOperations.TrailingZeroCount(mask) / sizeof(ushort));
nint charPos = (nint)(uint.TrailingZeroCount(mask) / sizeof(ushort));
if (EqualsIgnoreCase(ref Unsafe.Add(ref searchSpace, offset + charPos), ref valueRef, value.Length))
{
// Match! Return the index.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static int IndexOf(ref char searchSpace, int searchSpaceLength, ref char
uint mask = cmpAnd.ExtractMostSignificantBits();
do
{
nint charPos = (nint)((uint)BitOperations.TrailingZeroCount(mask) / sizeof(ushort));
nint charPos = (nint)(uint.TrailingZeroCount(mask) / sizeof(ushort));
if (valueLength == 2 || // we already matched two chars
SequenceEqual(
ref Unsafe.As<char, byte>(ref Unsafe.Add(ref searchSpace, offset + charPos)),
Expand Down Expand Up @@ -176,7 +176,7 @@ public static int IndexOf(ref char searchSpace, int searchSpaceLength, ref char
uint mask = cmpAnd.ExtractMostSignificantBits();
do
{
nint charPos = (nint)((uint)BitOperations.TrailingZeroCount(mask) / sizeof(ushort));
nint charPos = (nint)(uint.TrailingZeroCount(mask) / sizeof(ushort));
if (valueLength == 2 || // we already matched two chars
SequenceEqual(
ref Unsafe.As<char, byte>(ref Unsafe.Add(ref searchSpace, offset + charPos)),
Expand Down

0 comments on commit 887ccac

Please sign in to comment.