use as_bytes().to_vec() instead of bytes().collect()

copying a slice into a vec should be easier to optimize by the complier than collecting a byte iteration into a vec
This commit is contained in:
Skgland
2025-11-18 22:01:42 +01:00
committed by Bennet Bleßmann
parent a283c8bdc2
commit 248b05c992

View File

@@ -3303,7 +3303,7 @@ impl Machine {
bytes.push(c as u8); bytes.push(c as u8);
} }
} else { } else {
bytes = string.as_str().bytes().collect(); bytes = string.as_str().as_bytes().to_vec();
} }
match stream.write_all(&bytes) { match stream.write_all(&bytes) {
@@ -4420,7 +4420,7 @@ impl Machine {
let address_data = self.deref_register(5); let address_data = self.deref_register(5);
let mut bytes: Vec<u8> = Vec::new(); let mut bytes: Vec<u8> = Vec::new();
if let Some(string) = self.machine_st.value_to_str_like(address_data) { if let Some(string) = self.machine_st.value_to_str_like(address_data) {
bytes = string.as_str().bytes().collect(); bytes = string.as_str().as_bytes().to_vec();
} }
let stub_gen = || functor_stub(atom!("http_open"), 3); let stub_gen = || functor_stub(atom!("http_open"), 3);
@@ -9309,7 +9309,7 @@ impl Machine {
let data = self.machine_st.value_to_str_like(data_arg).unwrap(); let data = self.machine_st.value_to_str_like(data_arg).unwrap();
match encoding { match encoding {
atom!("utf8") => data.as_str().bytes().collect(), atom!("utf8") => data.as_str().as_bytes().to_vec(),
atom!("octet") => data.as_str().chars().map(|c| c as u8).collect(), atom!("octet") => data.as_str().chars().map(|c| c as u8).collect(),
_ => { _ => {
unreachable!() unreachable!()