From 5ab83de797f30a80b8296cfc5e4c52fdd8cba9ba Mon Sep 17 00:00:00 2001 From: Chris Richards Date: Mon, 23 Nov 2026 13:31:29 +0000 Subject: [PATCH] Parse numeric fields straight from the record bytes on .NET 8+ AsciiFieldParser copied each numeric field into a stack-allocated char span before parsing. .NET 8 and later can parse the bytes directly, so skip the copy there. netstandard2.1 keeps the existing path. Co-Authored-By: Claude Fable 5.2 --- src/DbfDataReader/AsciiFieldParser.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/DbfDataReader/AsciiFieldParser.cs b/src/DbfDataReader/AsciiFieldParser.cs index ca8e181..0660406 100644 --- a/src/DbfDataReader/AsciiFieldParser.cs +++ b/src/DbfDataReader/AsciiFieldParser.cs @@ -13,33 +13,49 @@ internal static class AsciiFieldParser public static bool TryParse(ReadOnlySpan bytes, NumberStyles styles, NumberFormatInfo format, out decimal value) { +#if NET8_0_OR_GREATER + return decimal.TryParse(bytes, styles, format, out value); +#else Span chars = stackalloc char[bytes.Length]; Decode(bytes, chars); return decimal.TryParse(chars, styles, format, out value); +#endif } public static bool TryParse(ReadOnlySpan bytes, NumberStyles styles, NumberFormatInfo format, out int value) { +#if NET8_0_OR_GREATER + return int.TryParse(bytes, styles, format, out value); +#else Span chars = stackalloc char[bytes.Length]; Decode(bytes, chars); return int.TryParse(chars, styles, format, out value); +#endif } public static bool TryParse(ReadOnlySpan bytes, NumberStyles styles, NumberFormatInfo format, out long value) { +#if NET8_0_OR_GREATER + return long.TryParse(bytes, styles, format, out value); +#else Span chars = stackalloc char[bytes.Length]; Decode(bytes, chars); return long.TryParse(chars, styles, format, out value); +#endif } public static bool TryParse(ReadOnlySpan bytes, NumberStyles styles, NumberFormatInfo format, out float value) { +#if NET8_0_OR_GREATER + return float.TryParse(bytes, styles, format, out value); +#else Span chars = stackalloc char[bytes.Length]; Decode(bytes, chars); return float.TryParse(chars, styles, format, out value); +#endif } public static bool TryParseDate(ReadOnlySpan bytes, string dateFormat, out DateTime value)