Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speeding up write_significand() #2499

Merged
merged 1 commit into from
Oct 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1704,14 +1704,20 @@ inline auto write_significand(Char* out, UInt significand, int significand_size,
int integral_size, Char decimal_point) -> Char* {
if (!decimal_point)
return format_decimal(out, significand, significand_size).end;
auto end = format_decimal(out + 1, significand, significand_size).end;
if (integral_size == 1) {
out[0] = out[1];
} else {
std::uninitialized_copy_n(out + 1, integral_size,
make_checked(out, to_unsigned(integral_size)));
out += significand_size + 1;
Char* end = out;
int floating_size = significand_size - integral_size;
for(int i = floating_size / 2; i > 0; --i) {
out -= 2;
copy2(out, digits2(significand % 100));
significand /= 100;
}
if (floating_size % 2 != 0) {
*--out = static_cast<Char>('0' + significand % 10);
significand /= 10;
}
out[integral_size] = decimal_point;
*--out = decimal_point;
format_decimal(out - integral_size, significand, integral_size);
return end;
}

Expand Down