From a283c8bdc2606dc4d866b282cdd64f75c6d74e0b Mon Sep 17 00:00:00 2001 From: Skgland Date: Tue, 18 Nov 2025 21:59:55 +0100 Subject: [PATCH] remove some uncessary allocations/copies --- src/indexing.rs | 10 +++------- src/machine/args.rs | 4 +--- src/machine/lib_machine/mod.rs | 6 +++--- src/machine/loader.rs | 4 +--- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/indexing.rs b/src/indexing.rs index 345533ad..a1105fdf 100644 --- a/src/indexing.rs +++ b/src/indexing.rs @@ -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 CodeOffsets { str_loc, ))); - prelude.into_iter().collect() + prelude.into() } } diff --git a/src/machine/args.rs b/src/machine/args.rs index 6e24c87a..02a9d332 100644 --- a/src/machine/args.rs +++ b/src/machine/args.rs @@ -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 = env::args().collect(); Self { - add_history: !args.contains("--no-add-history"), + add_history: env::args().all(|arg| arg != "--no-add-history"), } } } diff --git a/src/machine/lib_machine/mod.rs b/src/machine/lib_machine/mod.rs index 7527c05c..810c607d 100644 --- a/src/machine/lib_machine/mod.rs +++ b/src/machine/lib_machine/mod.rs @@ -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::>().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::>().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::>().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) diff --git a/src/machine/loader.rs b/src/machine/loader.rs index 763fa447..fded231b 100644 --- a/src/machine/loader.rs +++ b/src/machine/loader.rs @@ -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::(), + functor_stub(atom!(":"), 2), ); self.machine_st -- 2.54.0