TryParseBoolean: Implement a case-sensitive fast parse that reads and compares to constant
+ private unsafe static bool IsTrue(byte* utf8Bytes, int length)
+ {
+ if (length < 4)
+ return false;
+
+ byte firstChar = utf8Bytes[0];
+ if (firstChar != 't' && firstChar != 'T')
The current implementation of TryParseBoolean has a lot of branches. This can be made more performant by comparing against a constant like in Jan's suggestion: return (span.ReadInt32LittleEndian() & ~0x20202020) == 'T' + 0x100 * 'R' + 0x10000 * 'U' + 0x1000000 * 'E';
Ati, might be worth measuring the perf impact and either doing the change or closing this issue.
span.ReadInt32LittleEndian() might have been the feature I was looking for here:
https://github.com/dotnet/corefx/blob/ba0e14d957cd2fed3e1dec54d2c5f2a92a746c74/src/System.Memory/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.R.cs#L33
should see if this parser works faster using ReadInt32LittleEndian.
@AtsushiKan Do you plan on merging your proposed commit into corefx master? The change looks fine.
Oh, right, that fell through the cracks over vacation. Sure, I can open up a PR.
Fixed.