diff --git a/src/Parlot/Compilation/ExpressionHelper.cs b/src/Parlot/Compilation/ExpressionHelper.cs index 4da40c7..a59ad92 100644 --- a/src/Parlot/Compilation/ExpressionHelper.cs +++ b/src/Parlot/Compilation/ExpressionHelper.cs @@ -31,8 +31,10 @@ public static class ExpressionHelper internal static readonly ConstructorInfo TextSpan_Constructor = typeof(TextSpan).GetConstructor([typeof(string), typeof(int), typeof(int)])!; + internal static readonly MethodInfo ReadOnlySpan_ToString = typeof(ReadOnlySpan).GetMethod(nameof(ToString), [])!; + internal static readonly MethodInfo MemoryExtensions_AsSpan = typeof(MemoryExtensions).GetMethod(nameof(MemoryExtensions.AsSpan), [typeof(string)])!; - + public static Expression ArrayEmpty() => ((Expression>)(() => Array.Empty())).Body; public static Expression New() where T : new() => ((Expression>)(() => new T())).Body; diff --git a/src/Parlot/Fluent/NumberLiteralBase.cs b/src/Parlot/Fluent/NumberLiteralBase.cs index 4ed9183..c3e3534 100644 --- a/src/Parlot/Fluent/NumberLiteralBase.cs +++ b/src/Parlot/Fluent/NumberLiteralBase.cs @@ -14,7 +14,6 @@ namespace Parlot.Fluent; public abstract class NumberLiteralBase : Parser, ICompilable { private static readonly MethodInfo _defaultTryParseMethodInfo = typeof(T).GetMethod("TryParse", [typeof(string), typeof(NumberStyles), typeof(IFormatProvider), typeof(T).MakeByRefType()])!; - private static readonly MethodInfo _rosToString = typeof(ReadOnlySpan).GetMethod(nameof(ToString), [])!; private readonly char _decimalSeparator; private readonly char _groupSeparator; @@ -26,8 +25,6 @@ public abstract class NumberLiteralBase : Parser, ICompilable private readonly bool _allowGroupSeparator; private readonly bool _allowExponent; - private delegate (bool, T) TryParseDelegate(); - public abstract bool TryParseNumber(ReadOnlySpan s, NumberStyles style, IFormatProvider provider, out T value); public NumberLiteralBase(NumberOptions numberOptions = NumberOptions.Number, char decimalSeparator = NumberLiterals.DefaultDecimalSeparator, char groupSeparator = NumberLiterals.DefaultGroupSeparator, MethodInfo? tryParseMethodInfo = null) @@ -62,8 +59,6 @@ public override bool Parse(ParseContext context, ref ParseResult result) { var end = context.Scanner.Cursor.Offset; - var sourceToParse = number.ToString(); - if (TryParseNumber(number, _numberStyles, _culture, out T value)) { result.Set(start, end, value); @@ -115,7 +110,7 @@ public CompilationResult Compile(CompilationContext context) Expression.Assign(result.Success, Expression.Call( _tryParseMethodInfo, - Expression.Call(numberSpan, _rosToString), + Expression.Call(numberSpan, ExpressionHelper.ReadOnlySpan_ToString), numberStyles, culture, result.Value)