Skip to content

Commit 2e8b632

Browse files
committed
Auto merge of rust-lang#136974 - m-ou-se:fmt-options-64-bit, r=scottmcm
Reduce FormattingOptions to 64 bits This is part of rust-lang#99012 This reduces FormattingOptions from 6-7 machine words (384 bits on 64-bit platforms, 224 bits on 32-bit platforms) to just 64 bits (a single register on 64-bit platforms). Before: ```rust pub struct FormattingOptions { flags: u32, // only 6 bits used fill: char, align: Option<Alignment>, width: Option<usize>, precision: Option<usize>, } ``` After: ```rust pub struct FormattingOptions { /// Bits: /// - 0-20: fill character (21 bits, a full `char`) /// - 21: `+` flag /// - 22: `-` flag /// - 23: `#` flag /// - 24: `0` flag /// - 25: `x?` flag /// - 26: `X?` flag /// - 27: Width flag (if set, the width field below is used) /// - 28: Precision flag (if set, the precision field below is used) /// - 29-30: Alignment (0: Left, 1: Right, 2: Center, 3: Unknown) /// - 31: Always set to 1 flags: u32, /// Width if width flag above is set. Otherwise, always 0. width: u16, /// Precision if precision flag above is set. Otherwise, always 0. precision: u16, } ```
2 parents 5ab8085 + 73795ed commit 2e8b632

File tree

4 files changed

+254
-187
lines changed

4 files changed

+254
-187
lines changed

core/src/fmt/float.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ where
8686
true => flt2dec::Sign::MinusPlus,
8787
};
8888

89-
if let Some(precision) = fmt.options.precision {
89+
if let Some(precision) = fmt.options.get_precision() {
9090
float_to_decimal_common_exact(fmt, num, sign, precision)
9191
} else {
9292
let min_precision = 0;
@@ -162,7 +162,7 @@ where
162162
true => flt2dec::Sign::MinusPlus,
163163
};
164164

165-
if let Some(precision) = fmt.options.precision {
165+
if let Some(precision) = fmt.options.get_precision() {
166166
// 1 integral digit + `precision` fractional digits = `precision + 1` total digits
167167
float_to_exponential_common_exact(fmt, num, sign, precision + 1, upper)
168168
} else {
@@ -180,7 +180,7 @@ where
180180
true => flt2dec::Sign::MinusPlus,
181181
};
182182

183-
if let Some(precision) = fmt.options.precision {
183+
if let Some(precision) = fmt.options.get_precision() {
184184
// this behavior of {:.PREC?} predates exponential formatting for {:?}
185185
float_to_decimal_common_exact(fmt, num, sign, precision)
186186
} else {

0 commit comments

Comments
 (0)