@@ -207,7 +207,10 @@ macro_rules! impl_Display {
207
207
fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
208
208
#[ cfg( not( feature = "optimize_for_size" ) ) ]
209
209
{
210
- self . _fmt( true , f)
210
+ const SIZE : usize = $unsigned:: MAX . ilog( 10 ) as usize + 1 ;
211
+ let mut buf = [ MaybeUninit :: <u8 >:: uninit( ) ; SIZE ] ;
212
+
213
+ f. pad_integral( true , "" , self . _fmt( & mut buf, SIZE ) )
211
214
}
212
215
#[ cfg( feature = "optimize_for_size" ) ]
213
216
{
@@ -221,7 +224,10 @@ macro_rules! impl_Display {
221
224
fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
222
225
#[ cfg( not( feature = "optimize_for_size" ) ) ]
223
226
{
224
- return self . unsigned_abs( ) . _fmt( * self >= 0 , f) ;
227
+ const SIZE : usize = $signed:: MAX . ilog( 10 ) as usize + 1 ;
228
+ let mut buf = [ MaybeUninit :: <u8 >:: uninit( ) ; SIZE ] ;
229
+
230
+ f. pad_integral( * self >= 0 , "" , self . unsigned_abs( ) . _fmt( & mut buf, SIZE ) )
225
231
}
226
232
#[ cfg( feature = "optimize_for_size" ) ]
227
233
{
@@ -232,11 +238,14 @@ macro_rules! impl_Display {
232
238
233
239
#[ cfg( not( feature = "optimize_for_size" ) ) ]
234
240
impl $unsigned {
235
- fn _fmt( mut self , is_nonnegative: bool , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
236
- const SIZE : usize = $unsigned:: MAX . ilog( 10 ) as usize + 1 ;
237
- let mut buf = [ MaybeUninit :: <u8 >:: uninit( ) ; SIZE ] ;
238
- let mut curr = SIZE ;
239
- let buf_ptr = MaybeUninit :: slice_as_mut_ptr( & mut buf) ;
241
+ #[ doc( hidden) ]
242
+ #[ unstable(
243
+ feature = "fmt_internals" ,
244
+ reason = "internal routines only exposed for testing" ,
245
+ issue = "none"
246
+ ) ]
247
+ pub fn _fmt<' a>( mut self , buf: & ' a mut [ MaybeUninit :: <u8 >] , mut curr: usize ) -> & ' a str {
248
+ let buf_ptr = MaybeUninit :: slice_as_mut_ptr( buf) ;
240
249
let lut_ptr = DEC_DIGITS_LUT . as_ptr( ) ;
241
250
242
251
// SAFETY: Since `d1` and `d2` are always less than or equal to `198`, we
@@ -296,11 +305,10 @@ macro_rules! impl_Display {
296
305
297
306
// SAFETY: `curr` > 0 (since we made `buf` large enough), and all the chars are valid
298
307
// UTF-8 since `DEC_DIGITS_LUT` is
299
- let buf_slice = unsafe {
308
+ unsafe {
300
309
str :: from_utf8_unchecked(
301
310
slice:: from_raw_parts( buf_ptr. add( curr) , buf. len( ) - curr) )
302
- } ;
303
- f. pad_integral( is_nonnegative, "" , buf_slice)
311
+ }
304
312
}
305
313
} ) *
306
314
0 commit comments