]> Repositorios git - scryer-prolog.git/commitdiff
remove some uncessary allocations/copies
authorSkgland <[email protected]>
Tue, 18 Nov 2025 20:59:55 +0000 (21:59 +0100)
committerBennet Bleßmann <[email protected]>
Wed, 19 Nov 2025 18:23:41 +0000 (19:23 +0100)
src/indexing.rs
src/machine/args.rs
src/machine/lib_machine/mod.rs
src/machine/loader.rs

index 345533adc6c3c61100e29b3f04c2ddb88235a9b2..a1105fdfa107054eaf025238faa87b6acd1fc3b8 100644 (file)
@@ -1328,9 +1328,7 @@ impl Indexer for DynamicCodeIndices {
         for (key, code) in indices.into_iter() {
             if code.len() > 1 {
                 index_locs.insert(key, IndexingCodePtr::Internal(prelude.len() + 1));
-                prelude.push_back(IndexingLine::DynamicIndexedChoice(
-                    code.into_iter().collect(),
-                ));
+                prelude.push_back(IndexingLine::DynamicIndexedChoice(code));
             } else if let Some(i) = code.front() {
                 index_locs.insert(key, IndexingCodePtr::DynamicExternal(*i));
             }
@@ -1369,9 +1367,7 @@ impl Indexer for DynamicCodeIndices {
     ) -> IndexingCodePtr {
         if lists.len() > 1 {
             let lists = std::mem::take(lists);
-            prelude.push_back(IndexingLine::DynamicIndexedChoice(
-                lists.into_iter().collect(),
-            ));
+            prelude.push_back(IndexingLine::DynamicIndexedChoice(lists));
             IndexingCodePtr::Internal(1)
         } else {
             lists
@@ -1548,6 +1544,6 @@ impl<I: Indexer> CodeOffsets<I> {
             str_loc,
         )));
 
-        prelude.into_iter().collect()
+        prelude.into()
     }
 }
index 6e24c87a2f619711ea1adc50e2ecef16ed0eb921..02a9d332fb0a4baafc323b463c529486f1779eab 100644 (file)
@@ -1,4 +1,3 @@
-use std::collections::BTreeSet;
 use std::env;
 
 #[derive(Debug)]
@@ -8,9 +7,8 @@ pub struct MachineArgs {
 
 impl MachineArgs {
     pub fn new() -> Self {
-        let args: BTreeSet<String> = env::args().collect();
         Self {
-            add_history: !args.contains("--no-add-history"),
+            add_history: env::args().all(|arg| arg != "--no-add-history"),
         }
     }
 }
index 7527c05c2857baaa61464645d4428ceb44c81a57..810c607dc87fa90c910cd5421afb16dbb58a088b 100644 (file)
@@ -224,14 +224,14 @@ impl Term {
 
                     let list = match tail {
                         Term::Atom(atom) if atom == "[]" => match head {
-                            Term::Atom(ref a) if a.chars().collect::<Vec<_>>().len() == 1 => {
+                            Term::Atom(ref a) if a.chars().count() == 1 => {
                                 // Handle lists of char as strings
                                 Term::String(a.to_string())
                             }
                             _ => Term::List(vec![head]),
                         },
                         Term::List(elems) if elems.is_empty() => match head {
-                            Term::Atom(ref a) if a.chars().collect::<Vec<_>>().len() == 1 => {
+                            Term::Atom(ref a) if a.chars().count() == 1 => {
                                 // Handle lists of char as strings
                                 Term::String(a.to_string())
                             },
@@ -242,7 +242,7 @@ impl Term {
                             Term::List(elems)
                         },
                         Term::String(mut elems) => match head {
-                            Term::Atom(ref a) if a.chars().collect::<Vec<_>>().len() == 1 => {
+                            Term::Atom(ref a) if a.chars().count() == 1 => {
                                 // Handle lists of char as strings
                                 elems.insert(0, a.chars().next().unwrap());
                                 Term::String(elems)
index 763fa4478361d727070b1464b161fbf8cf183c8a..fded231b0b97e8e2c6ad66d4f1fd5256ce228f9b 100644 (file)
@@ -1842,9 +1842,7 @@ impl Machine {
             let err = self.machine_st.permission_error(
                 Permission::Modify,
                 atom!("static_procedure"),
-                functor_stub(atom!(":"), 2)
-                    .into_iter()
-                    .collect::<MachineStub>(),
+                functor_stub(atom!(":"), 2),
             );
 
             self.machine_st