File tree 2 files changed +4
-3
lines changed
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> {
652
652
// There are some arguments, so any additional push
653
653
// will reallocate the string. To avoid that,
654
654
// 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)
657
658
}
658
659
}
659
660
}
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ fn test_estimated_capacity() {
26
26
assert_eq ! ( format_args!( "Hello" ) . estimated_capacity( ) , 5 ) ;
27
27
assert_eq ! ( format_args!( "Hello, {}!" , { "" } ) . estimated_capacity( ) , 16 ) ;
28
28
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 ) ;
30
30
}
31
31
32
32
#[ test]
You can’t perform that action at this time.
0 commit comments