Skip to content

Commit

Permalink
Use smallvec crate in pubgrub
Browse files Browse the repository at this point in the history
  • Loading branch information
x-hgg-x committed Nov 20, 2024
1 parent cc47677 commit a1ab16e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 243 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ keywords = ["dependency", "pubgrub", "semver", "solver", "version"]
categories = ["algorithms"]
include = ["Cargo.toml", "LICENSE", "README.md", "src/**", "tests/**", "examples/**", "benches/**"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
indexmap = "2.6.0"
# for debug logs in tests
log = "0.4.22"
priority-queue = "2.1.1"
rustc-hash = ">=1.0.0, <3.0.0"
serde = { version = "1.0", features = ["derive"], optional = true }
smallvec = { version = "1.13.2", features = ["union"] }
thiserror = "2.0"
version-ranges = { version = "0.1.0", path = "version-ranges" }

Expand Down
10 changes: 6 additions & 4 deletions src/internal/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use std::sync::Arc;

use smallvec::SmallVec;

use crate::{
internal::{
Arena, DecisionLevel, IncompDpId, Incompatibility, PartialSolution, Relation,
SatisfierSearch, SmallVec,
SatisfierSearch,
},
DependencyProvider, DerivationTree, Map, PackageArena, PackageId, Set, Term, VersionIndex,
VersionSet,
Expand All @@ -26,7 +28,7 @@ pub(crate) struct State<DP: DependencyProvider> {
/// All incompatibilities expressing dependencies,
/// with common dependents merged.
#[allow(clippy::type_complexity)]
merged_dependencies: Map<(PackageId, PackageId), SmallVec<IncompDpId<DP>>>,
merged_dependencies: Map<(PackageId, PackageId), SmallVec<[IncompDpId<DP>; 4]>>,

/// Partial solution.
/// TODO: remove pub.
Expand All @@ -38,7 +40,7 @@ pub(crate) struct State<DP: DependencyProvider> {
/// This is a stack of work to be done in `unit_propagation`.
/// It can definitely be a local variable to that method, but
/// this way we can reuse the same allocation for better performance.
unit_propagation_buffer: SmallVec<PackageId>,
unit_propagation_buffer: Vec<PackageId>,
}

impl<DP: DependencyProvider> State<DP> {
Expand All @@ -57,7 +59,7 @@ impl<DP: DependencyProvider> State<DP> {
incompatibilities,
partial_solution: PartialSolution::empty(),
incompatibility_store,
unit_propagation_buffer: SmallVec::Empty,
unit_propagation_buffer: Vec::new(),
merged_dependencies: Map::default(),
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ mod core;
mod incompatibility;
mod partial_solution;
mod small_map;
mod small_vec;

pub(crate) use arena::{Arena, Id};
pub(crate) use core::State;
pub(crate) use incompatibility::{IncompDpId, IncompId, Incompatibility, Relation};
pub(crate) use partial_solution::{DecisionLevel, PartialSolution, SatisfierSearch};
pub(crate) use small_map::SmallMap;
pub(crate) use small_vec::SmallVec;
7 changes: 4 additions & 3 deletions src/internal/partial_solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use std::hash::BuildHasherDefault;

use priority_queue::PriorityQueue;
use rustc_hash::FxHasher;
use smallvec::{smallvec, SmallVec};

use crate::Map;
use crate::{
internal::{Arena, IncompDpId, IncompId, Incompatibility, Relation, SmallMap, SmallVec},
internal::{Arena, IncompDpId, IncompId, Incompatibility, Relation, SmallMap},
DependencyProvider, FxIndexMap, PackageArena, PackageId, SelectedDependencies, Term,
VersionIndex, VersionSet,
};
Expand Down Expand Up @@ -97,7 +98,7 @@ impl<'a, DP: DependencyProvider> Display for PartialSolutionDisplay<'a, DP> {
struct PackageAssignments<M: Eq + Clone + Debug + Display> {
smallest_decision_level: DecisionLevel,
highest_decision_level: DecisionLevel,
dated_derivations: SmallVec<DatedDerivation<M>>,
dated_derivations: SmallVec<[DatedDerivation<M>; 1]>,
assignments_intersection: AssignmentsIntersection,
}

Expand Down Expand Up @@ -298,7 +299,7 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
v.insert(PackageAssignments {
smallest_decision_level: self.current_decision_level,
highest_decision_level: self.current_decision_level,
dated_derivations: SmallVec::One([dated_derivation]),
dated_derivations: smallvec![dated_derivation],
assignments_intersection: AssignmentsIntersection::derivations(term),
});
}
Expand Down
232 changes: 0 additions & 232 deletions src/internal/small_vec.rs

This file was deleted.

0 comments on commit a1ab16e

Please sign in to comment.