Skip to content

Commit 34e1e17

Browse files
committed
Don't reload length in String::push
Same as in Vec::push_mut, we get `.len()` once at the start since it won't change in the `reserve()` call. Saves reloading the length after the allocation: https://godbolt.org/z/W3G165Gd7
1 parent d4f7856 commit 34e1e17

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

library/alloc/src/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ impl String {
14201420

14211421
// SAFETY: Just reserved capacity for at least the length needed to encode `ch`.
14221422
unsafe {
1423-
core::char::encode_utf8_raw_unchecked(ch as u32, self.vec.as_mut_ptr().add(self.len()));
1423+
core::char::encode_utf8_raw_unchecked(ch as u32, self.vec.as_mut_ptr().add(len));
14241424
self.vec.set_len(len + ch_len);
14251425
}
14261426
}

0 commit comments

Comments
 (0)