Merge pull request #419 from fastfloat/fix-418-struct-layout

Reorder parsed_number_string_t fields to avoid padding (fixes #418)
This commit is contained in:
Daniel Lemire 2026-10-04 11:59:23 -04:00 committed by GitHub
commit 3e4f80fcc4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -308,13 +308,16 @@ template <typename UC> struct parsed_number_string_t {
int64_t exponent{0};
uint64_t mantissa{0};
UC const *lastmatch{nullptr};
// The field order matters: placing 'error' next to the booleans avoids
// padding, keeping the struct at 64 bytes on 64-bit systems instead of 72.
// See https://github.com/fastfloat/fast_float/issues/418
parse_error error{parse_error::no_error};
bool negative{false};
bool valid{false};
bool too_many_digits{false};
// contains the range of the significant digits
span<UC const> integer{}; // non-nullable
span<UC const> fraction{}; // nullable
parse_error error{parse_error::no_error};
};
using byte_span = span<char const>;

View File

@ -84,6 +84,12 @@ char const *round_name(int d) {
}
}
// Guard against padding regressions that hurt performance.
// See https://github.com/fastfloat/fast_float/issues/418
static_assert(sizeof(void *) != 8 ||
sizeof(fast_float::parsed_number_string_t<char>) <= 64,
"parsed_number_string_t should fit in 64 bytes");
#define FASTFLOAT_STR(x) #x
#define SHOW_DEFINE(x) printf("%s='%s'\n", #x, FASTFLOAT_STR(x))