]> git.lizzy.rs Git - rust.git/commitdiff
Avoid unnecessary calculation
authorShotaro Yamada <sinkuu@sinkuu.xyz>
Sun, 4 Mar 2018 00:43:29 +0000 (09:43 +0900)
committerShotaro Yamada <sinkuu@sinkuu.xyz>
Sun, 4 Mar 2018 00:43:29 +0000 (09:43 +0900)
src/liballoc/str.rs

index 6d153bf02b3ba2d2593ff53e4b1e5618504349af..64e815b1fbaa5d92b14703e3699c6f087513e3e0 100644 (file)
@@ -2113,9 +2113,9 @@ pub fn repeat(&self, n: usize) -> String {
                     (buf.as_mut_ptr() as *mut u8).add(buf.len()),
                     rem_len,
                 );
-                // `buf.len() + rem_len` equals to `buf.capacity()` (`self.len() * n`).
-                let buf_len = buf.len();
-                buf.set_len(buf_len + rem_len);
+                // `buf.len() + rem_len` equals to `buf.capacity()` (`self.len() * n`).
+                let buf_cap = buf.capacity();
+                buf.set_len(buf_cap);
             }
         }