From 4739aaf058cc1438b96deca7f6a0e64152c265a4 Mon Sep 17 00:00:00 2001 From: konstin Date: Wed, 11 Dec 2024 18:42:18 +0100 Subject: [PATCH] Return `Id` over `ID` It's more efficient to return a u32 than a reference, and it avoids a borrow when returning it. --- src/internal/core.rs | 4 ++-- src/internal/incompatibility.rs | 16 +++++++++------- src/internal/partial_solution.rs | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/internal/core.rs b/src/internal/core.rs index a4c189bc..6f70d04c 100644 --- a/src/internal/core.rs +++ b/src/internal/core.rs @@ -275,7 +275,7 @@ impl State { .map(|m| (past, m)) }) { let new = self.incompatibility_store.alloc(merged); - for (&pkg, _) in self.incompatibility_store[new].iter() { + for (pkg, _) in self.incompatibility_store[new].iter() { self.incompatibilities .entry(pkg) .or_default() @@ -287,7 +287,7 @@ impl State { deps_lookup.push(id); } } - for (&pkg, term) in self.incompatibility_store[id].iter() { + for (pkg, term) in self.incompatibility_store[id].iter() { if cfg!(debug_assertions) { assert_ne!(term, &crate::term::Term::any()); } diff --git a/src/internal/incompatibility.rs b/src/internal/incompatibility.rs index 428ab597..1417fb9e 100644 --- a/src/internal/incompatibility.rs +++ b/src/internal/incompatibility.rs @@ -246,8 +246,10 @@ impl Incompatibilit } /// Iterate over packages. - pub(crate) fn iter(&self) -> impl Iterator, &Term)> { - self.package_terms.iter() + pub(crate) fn iter(&self) -> impl Iterator, &Term)> { + self.package_terms + .iter() + .map(|(package, term)| (*package, term)) } // Reporting ############################################################### @@ -348,17 +350,17 @@ impl Incompatibilit [] => "version solving failed".into(), // TODO: special case when that unique package is root. [(package, Term::Positive(range))] => { - format!("{} {} is forbidden", package_store[**package], range) + format!("{} {} is forbidden", package_store[*package], range) } [(package, Term::Negative(range))] => { - format!("{} {} is mandatory", package_store[**package], range) + format!("{} {} is mandatory", package_store[*package], range) } [(p_pos, Term::Positive(r_pos)), (p_neg, Term::Negative(r_neg))] | [(p_neg, Term::Negative(r_neg)), (p_pos, Term::Positive(r_pos))] => { External::<_, _, M>::FromDependencyOf( - &package_store[**p_pos], + &package_store[*p_pos], r_pos.clone(), - &package_store[**p_neg], + &package_store[*p_neg], r_neg.clone(), ) .to_string() @@ -366,7 +368,7 @@ impl Incompatibilit slice => { let str_terms: Vec<_> = slice .iter() - .map(|(p, t)| format!("{} {}", package_store[**p], t)) + .map(|(p, t)| format!("{} {}", package_store[*p], t)) .collect(); str_terms.join(", ") + " are incompatible" } diff --git a/src/internal/partial_solution.rs b/src/internal/partial_solution.rs index c6328aac..d565cd30 100644 --- a/src/internal/partial_solution.rs +++ b/src/internal/partial_solution.rs @@ -459,7 +459,7 @@ impl PartialSolution { package_assignments: &FnvIndexMap, PackageAssignments>, ) -> SatisfiedMap { let mut satisfied = SmallMap::Empty; - for (&package, incompat_term) in incompat.iter() { + for (package, incompat_term) in incompat.iter() { let pa = package_assignments.get(&package).expect("Must exist"); satisfied.insert(package, pa.satisfier(package, &incompat_term.negate())); }