@@ -274,16 +274,12 @@ impl<'a> Arguments<'a> {
274
274
#[ unstable( feature = "fmt_internals" , reason = "internal to format_args!" ,
275
275
issue = "0" ) ]
276
276
pub fn estimated_capacity ( & self ) -> usize {
277
- // Using wrapping arithmetics in this function, because
278
- // wrong result is highly unlikely and doesn't cause unsafety.
279
- use :: num:: Wrapping as W ;
280
-
281
- let pieces_length: W < usize > = self . pieces . iter ( )
282
- . map ( |x| W ( x. len ( ) ) ) . sum ( ) ;
277
+ let pieces_length: usize = self . pieces . iter ( )
278
+ . map ( |x| x. len ( ) ) . sum ( ) ;
283
279
284
280
if self . args . is_empty ( ) {
285
- pieces_length. 0
286
- } else if self . pieces [ 0 ] == "" && pieces_length < W ( 16 ) {
281
+ pieces_length
282
+ } else if self . pieces [ 0 ] == "" && pieces_length < 16 {
287
283
// If the format string starts with an argument,
288
284
// don't preallocate anything, unless length
289
285
// of pieces is significant.
@@ -292,9 +288,8 @@ impl<'a> Arguments<'a> {
292
288
// There are some arguments, so any additional push
293
289
// will reallocate the string. To avoid that,
294
290
// we're "pre-doubling" the capacity here.
295
- ( pieces_length * W ( 2 ) ) . 0
291
+ pieces_length. checked_mul ( 2 ) . unwrap_or ( 0 )
296
292
}
297
-
298
293
}
299
294
}
300
295
0 commit comments