Skip to content

buffers in float_to_decimal_common seem to be a bit excessive #41234

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

Closed
bzbarsky opened this issue Apr 11, 2017 · 2 comments
Closed

buffers in float_to_decimal_common seem to be a bit excessive #41234

bzbarsky opened this issue Apr 11, 2017 · 2 comments

Comments

@bzbarsky
Copy link

float_to_decimal_common in src/libcore/fmt/float.rs does this:

let mut buf = [0; 1024];
let mut parts = [flt2dec::Part::Zero(0); 16];

and then passes buf and parts to flt2dec::to_exact_fixed_str or flt2dec::to_shortest_str

Looking at the docs for those functions at https://ticki.github.io/redocs/std/num/flt2dec/fn.to_exact_fixed_str.html and https://ticki.github.io/redocs/std/num/flt2dec/fn.to_shortest_str.html the "parts" array needs to have length at least 5, right? And the "buf" array needs to be at least 800+ for the to_exact_fixed_str case but only 17 (MAX_SIG_DIGITS) for the to_shortest_str case, afaict. Changing the to_shortest_str case to not use the huge buffer would probably help out https://users.rust-lang.org/t/excessive-stack-usage-for-formatting/8023 too.

Also, it's not clear to me that the "buf" scratch buffer needs to be zero-initialized. Does it?

@bzbarsky
Copy link
Author

Note that I'm poking at this a bit.

@bzbarsky
Copy link
Author

I spun off the zeroing thing into #41259 because I have a fix for that... we may still want to make the stackframe here smaller, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant