Skip to content

buffers in float_to_decimal_common seem to be a bit excessive #41234

@bzbarsky

Description

@bzbarsky

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?

Activity

bzbarsky

bzbarsky commented on Apr 12, 2017

@bzbarsky
Author

Note that I'm poking at this a bit.

bzbarsky

bzbarsky commented on Apr 12, 2017

@bzbarsky
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.

added a commit that references this issue on Apr 28, 2017
a21f616
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bzbarsky

        Issue actions

          buffers in float_to_decimal_common seem to be a bit excessive · Issue #41234 · rust-lang/rust