diff options
| author | Michał Krasnoborski <mkrdln@gmail.com> | 2017-02-02 03:38:12 +0100 |
|---|---|---|
| committer | Michał Krasnoborski <mkrdln@gmail.com> | 2017-02-02 03:38:12 +0100 |
| commit | ecda7f314fa79bbfbf2125c99fd66288ca83c875 (patch) | |
| tree | 7a54b37ad0b5f2505c9c6a13cd2b6a0001dd2258 /src | |
| parent | 7403ee9d07a1b096e9628871bd97e39f464c3aa5 (diff) | |
| download | rust-ecda7f314fa79bbfbf2125c99fd66288ca83c875.tar.gz rust-ecda7f314fa79bbfbf2125c99fd66288ca83c875.zip | |
remove the wrapping arithmetics
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/fmt/mod.rs | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index a870b6f88fb..a989f914db6 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -274,16 +274,12 @@ impl<'a> Arguments<'a> { #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "0")] pub fn estimated_capacity(&self) -> usize { - // Using wrapping arithmetics in this function, because - // wrong result is highly unlikely and doesn't cause unsafety. - use ::num::Wrapping as W; - - let pieces_length: W<usize> = self.pieces.iter() - .map(|x| W(x.len())).sum(); + let pieces_length: usize = self.pieces.iter() + .map(|x| x.len()).sum(); if self.args.is_empty() { - pieces_length.0 - } else if self.pieces[0] == "" && pieces_length < W(16) { + pieces_length + } else if self.pieces[0] == "" && pieces_length < 16 { // If the format string starts with an argument, // don't preallocate anything, unless length // of pieces is significant. @@ -292,9 +288,8 @@ impl<'a> Arguments<'a> { // There are some arguments, so any additional push // will reallocate the string. To avoid that, // we're "pre-doubling" the capacity here. - (pieces_length * W(2)).0 + pieces_length.checked_mul(2).unwrap_or(0) } - } } |
