Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Correct for element size
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Jan 25, 2019
1 parent ee69d66 commit 156f782
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/System.Private.CoreLib/shared/System/SpanHelpers.Char.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,9 @@ public static int IndexOf(ref char searchSpace, char value, int length)
continue;
}

// Find bitflag offset of first match and add to current offset
return offset + BitOps.TrailingZeroCount(matches);
// Find bitflag offset of first match and add to current offset,
// flags are in bytes so divide for chars
return offset + (BitOps.TrailingZeroCount(matches) / sizeof(char));
} while (lengthToExamine > offset);
}

Expand All @@ -283,8 +284,9 @@ public static int IndexOf(ref char searchSpace, char value, int length)
}
else
{
// Find bitflag offset of first match and add to current offset
return offset + BitOps.TrailingZeroCount(matches);
// Find bitflag offset of first match and add to current offset,
// flags are in bytes so divide for chars
return offset + (BitOps.TrailingZeroCount(matches) / sizeof(char));
}
}

Expand Down Expand Up @@ -315,8 +317,9 @@ public static int IndexOf(ref char searchSpace, char value, int length)
continue;
}

// Find bitflag offset of first match and add to current offset
return offset + BitOps.TrailingZeroCount(matches);
// Find bitflag offset of first match and add to current offset,
// flags are in bytes so divide for chars
return offset + (BitOps.TrailingZeroCount(matches) / sizeof(char));
}

if (offset < length)
Expand Down

0 comments on commit 156f782

Please sign in to comment.