Skip to content

Commit

Permalink
Merge pull request #33 from xin9le/feature/improve-numeric-check
Browse files Browse the repository at this point in the history
Speed up numeric check
  • Loading branch information
xin9le authored Sep 4, 2024
2 parents f62ca7b + fb38b76 commit 4fdfa22
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/libs/FastEnum.Core/FastEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,28 @@ public static bool TryParse<T>(ReadOnlySpan<char> value, bool ignoreCase, out T

#region Local Functions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool isNumeric(char c)
=> char.IsAsciiDigit(c) || (c is '-' or '+');
static bool isNumeric(char x)
{
// note:
// - In this case, there is no change in speed with or without sequential numbering.

return x switch
{
'+' => true, // 43
'-' => true, // 45
'0' => true, // 48
'1' => true,
'2' => true,
'3' => true,
'4' => true,
'5' => true,
'6' => true,
'7' => true,
'8' => true,
'9' => true,
_ => false,
};
}


[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down

0 comments on commit 4fdfa22

Please sign in to comment.