Skip to content

Commit 2499d81

Browse files
committed
fmt: use the minimum parts array size
The comments for flt2dec::to_shortest_str says that we only need a slice of length 5 for the parts array. Initializing a 16-part array is just wasted effort and wasted stack space. Other functions in the flt2dec module have similar comments, so we adjust the parts arrays passed to those functions accordingly.
1 parent a21f616 commit 2499d81

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/libcore/fmt/float.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn float_to_decimal_common_exact<T>(fmt: &mut Formatter, num: &T,
1919
where T: flt2dec::DecodableFloat
2020
{
2121
let mut buf = [0; 1024]; // enough for f32 and f64
22-
let mut parts = [flt2dec::Part::Zero(0); 16];
22+
let mut parts = [flt2dec::Part::Zero(0); 5];
2323
let formatted = flt2dec::to_exact_fixed_str(flt2dec::strategy::grisu::format_exact,
2424
*num, sign, precision,
2525
false, &mut buf, &mut parts);
@@ -34,7 +34,7 @@ fn float_to_decimal_common_shortest<T>(fmt: &mut Formatter,
3434
where T: flt2dec::DecodableFloat
3535
{
3636
let mut buf = [0; flt2dec::MAX_SIG_DIGITS]; // enough for f32 and f64
37-
let mut parts = [flt2dec::Part::Zero(0); 16];
37+
let mut parts = [flt2dec::Part::Zero(0); 5];
3838
let formatted = flt2dec::to_shortest_str(flt2dec::strategy::grisu::format_shortest,
3939
*num, sign, 0, false, &mut buf, &mut parts);
4040
fmt.pad_formatted_parts(&formatted)
@@ -68,7 +68,7 @@ fn float_to_exponential_common_exact<T>(fmt: &mut Formatter, num: &T,
6868
where T: flt2dec::DecodableFloat
6969
{
7070
let mut buf = [0; 1024]; // enough for f32 and f64
71-
let mut parts = [flt2dec::Part::Zero(0); 16];
71+
let mut parts = [flt2dec::Part::Zero(0); 7];
7272
let formatted = flt2dec::to_exact_exp_str(flt2dec::strategy::grisu::format_exact,
7373
*num, sign, precision,
7474
upper, &mut buf, &mut parts);
@@ -84,7 +84,7 @@ fn float_to_exponential_common_shortest<T>(fmt: &mut Formatter,
8484
where T: flt2dec::DecodableFloat
8585
{
8686
let mut buf = [0; flt2dec::MAX_SIG_DIGITS]; // enough for f32 and f64
87-
let mut parts = [flt2dec::Part::Zero(0); 16];
87+
let mut parts = [flt2dec::Part::Zero(0); 7];
8888
let formatted = flt2dec::to_shortest_exp_str(flt2dec::strategy::grisu::format_shortest, *num,
8989
sign, (0, 0), upper, &mut buf, &mut parts);
9090
fmt.pad_formatted_parts(&formatted)

0 commit comments

Comments
 (0)