Skip to content

Commit 8985f1f

Browse files
authored
Rollup merge of #155847 - DaniPopes:string-push-len, r=jhpratt
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
2 parents 4c59213 + 34e1e17 commit 8985f1f

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)