Skip to content

Commit f601c3e

Browse files
committed
auto merge of #15465 : SimonSapin/rust/patch-4, r=alexcrichton
`Vec::push_all` with a length 1 slice seems to have significant overhead compared to `Vec::push`. ``` test new_push_byte ... bench: 6985 ns/iter (+/- 487) = 17 MB/s test old_push_byte ... bench: 19335 ns/iter (+/- 1368) = 6 MB/s ``` ```rust extern crate test; use test::Bencher; static TEXT: &'static str = "\ Unicode est un standard informatique qui permet des échanges \ de textes dans différentes langues, à un niveau mondial."; #[bench] fn old_push_byte(bencher: &mut Bencher) { bencher.bytes = TEXT.len() as u64; bencher.iter(|| { let mut new = String::new(); for b in TEXT.bytes() { unsafe { new.as_mut_vec().push_all([b]) } } }) } #[bench] fn new_push_byte(bencher: &mut Bencher) { bencher.bytes = TEXT.len() as u64; bencher.iter(|| { let mut new = String::new(); for b in TEXT.bytes() { unsafe { new.as_mut_vec().push(b) } } }) } ```
2 parents 00a32f2 + ed3eee2 commit f601c3e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libcollections/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl String {
208208
/// Appends a byte to this string buffer. The caller must preserve the valid UTF-8 property.
209209
#[inline]
210210
pub unsafe fn push_byte(&mut self, byte: u8) {
211-
self.push_bytes([byte])
211+
self.vec.push(byte)
212212
}
213213

214214
/// Removes the last byte from the string buffer and returns it. Returns `None` if this string

0 commit comments

Comments
 (0)