]> Repositorios git - scryer-prolog.git/commitdiff
use as_bytes().to_vec() instead of bytes().collect()
authorSkgland <[email protected]>
Tue, 18 Nov 2025 21:01:42 +0000 (22:01 +0100)
committerBennet Bleßmann <[email protected]>
Wed, 19 Nov 2025 18:23:41 +0000 (19:23 +0100)
copying a slice into a vec should be easier to optimize by the complier than collecting a byte iteration into a vec

src/machine/system_calls.rs

index 5fc4088b1441d5d41098909430ab27d7d84b0428..4e1797a981de80cd183296f84330e92620f889ef 100644 (file)
@@ -3303,7 +3303,7 @@ impl Machine {
                     bytes.push(c as u8);
                 }
             } else {
-                bytes = string.as_str().bytes().collect();
+                bytes = string.as_str().as_bytes().to_vec();
             }
 
             match stream.write_all(&bytes) {
@@ -4420,7 +4420,7 @@ impl Machine {
         let address_data = self.deref_register(5);
         let mut bytes: Vec<u8> = Vec::new();
         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);
 
@@ -9309,7 +9309,7 @@ impl Machine {
         let data = self.machine_st.value_to_str_like(data_arg).unwrap();
 
         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(),
             _ => {
                 unreachable!()