File tree Expand file tree Collapse file tree 2 files changed +4
-3
lines changed Expand file tree Collapse file tree 2 files changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -652,8 +652,9 @@ impl<'a> Arguments<'a> {
652652 // There are some arguments, so any additional push
653653 // will reallocate the string. To avoid that,
654654 // we're "pre-doubling" the capacity here.
655- // It cannot overflow, because the maximum length is `isize::MAX`.
656- pieces_length * 2
655+ pieces_length
656+ . checked_add ( self . args . len ( ) . checked_mul ( 8 ) . unwrap_or ( 0 ) )
657+ . unwrap_or ( pieces_length)
657658 }
658659 }
659660}
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ fn test_estimated_capacity() {
2626 assert_eq ! ( format_args!( "Hello" ) . estimated_capacity( ) , 5 ) ;
2727 assert_eq ! ( format_args!( "Hello, {}!" , { "" } ) . estimated_capacity( ) , 16 ) ;
2828 assert_eq ! ( format_args!( "{}, hello!" , { "World" } ) . estimated_capacity( ) , 0 ) ;
29- assert_eq ! ( format_args!( "{}. 16-bytes piece" , { "World" } ) . estimated_capacity( ) , 32 ) ;
29+ assert_eq ! ( format_args!( "{}. 16-bytes piece" , { "World" } ) . estimated_capacity( ) , 24 ) ;
3030}
3131
3232#[ test]
You can’t perform that action at this time.
0 commit comments