Skip to content

Commit 7700f13

Browse files
committed
Use smallvec crate in pubgrub
1 parent 174ed21 commit 7700f13

File tree

6 files changed

+12
-243
lines changed

6 files changed

+12
-243
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ keywords = ["dependency", "pubgrub", "semver", "solver", "version"]
2020
categories = ["algorithms"]
2121
include = ["Cargo.toml", "LICENSE", "README.md", "src/**", "tests/**", "examples/**", "benches/**"]
2222

23-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
24-
2523
[dependencies]
2624
indexmap = "2.6.0"
2725
# for debug logs in tests
2826
log = "0.4.22"
2927
priority-queue = "2.1.1"
3028
rustc-hash = ">=1.0.0, <3.0.0"
3129
serde = { version = "1.0", features = ["derive"], optional = true }
30+
smallvec = { version = "1.13.2", features = ["union"] }
3231
thiserror = "2.0"
3332
version-ranges = { version = "0.1.0", path = "version-ranges" }
3433

src/internal/core.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
66
use std::sync::Arc;
77

8+
use smallvec::SmallVec;
9+
810
use crate::{
911
internal::{
1012
Arena, DecisionLevel, IncompDpId, Incompatibility, PartialSolution, Relation,
11-
SatisfierSearch, SmallVec,
13+
SatisfierSearch,
1214
},
1315
DependencyProvider, DerivationTree, Map, Package, PackageArena, Set, Term, VersionIndex,
1416
VersionSet,
@@ -26,7 +28,7 @@ pub(crate) struct State<DP: DependencyProvider> {
2628
/// All incompatibilities expressing dependencies,
2729
/// with common dependents merged.
2830
#[allow(clippy::type_complexity)]
29-
merged_dependencies: Map<(Package, Package), SmallVec<IncompDpId<DP>>>,
31+
merged_dependencies: Map<(Package, Package), SmallVec<[IncompDpId<DP>; 4]>>,
3032

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

4446
impl<DP: DependencyProvider> State<DP> {
@@ -55,7 +57,7 @@ impl<DP: DependencyProvider> State<DP> {
5557
incompatibilities,
5658
partial_solution: PartialSolution::empty(),
5759
incompatibility_store,
58-
unit_propagation_buffer: SmallVec::Empty,
60+
unit_propagation_buffer: Vec::new(),
5961
merged_dependencies: Map::default(),
6062
}
6163
}

src/internal/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ mod core;
77
mod incompatibility;
88
mod partial_solution;
99
mod small_map;
10-
mod small_vec;
1110

1211
pub(crate) use arena::{Arena, Id};
1312
pub(crate) use core::State;
1413
pub(crate) use incompatibility::{IncompDpId, IncompId, Incompatibility, Relation};
1514
pub(crate) use partial_solution::{DecisionLevel, PartialSolution, SatisfierSearch};
1615
pub(crate) use small_map::SmallMap;
17-
pub(crate) use small_vec::SmallVec;

src/internal/partial_solution.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ use std::hash::BuildHasherDefault;
77

88
use priority_queue::PriorityQueue;
99
use rustc_hash::FxHasher;
10+
use smallvec::{smallvec, SmallVec};
1011

1112
use crate::Map;
1213
use crate::{
13-
internal::{Arena, IncompDpId, IncompId, Incompatibility, Relation, SmallMap, SmallVec},
14+
internal::{Arena, IncompDpId, IncompId, Incompatibility, Relation, SmallMap},
1415
DependencyProvider, FxIndexMap, Package, PackageArena, SelectedDependencies, Term,
1516
VersionIndex, VersionSet,
1617
};
@@ -97,7 +98,7 @@ impl<'a, DP: DependencyProvider> Display for PartialSolutionDisplay<'a, DP> {
9798
struct PackageAssignments<M: Eq + Clone + Debug + Display> {
9899
smallest_decision_level: DecisionLevel,
99100
highest_decision_level: DecisionLevel,
100-
dated_derivations: SmallVec<DatedDerivation<M>>,
101+
dated_derivations: SmallVec<[DatedDerivation<M>; 1]>,
101102
assignments_intersection: AssignmentsIntersection,
102103
}
103104

@@ -298,7 +299,7 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
298299
v.insert(PackageAssignments {
299300
smallest_decision_level: self.current_decision_level,
300301
highest_decision_level: self.current_decision_level,
301-
dated_derivations: SmallVec::One([dated_derivation]),
302+
dated_derivations: smallvec![dated_derivation],
302303
assignments_intersection: AssignmentsIntersection::derivations(term),
303304
});
304305
}

src/internal/small_vec.rs

Lines changed: 0 additions & 232 deletions
This file was deleted.

0 commit comments

Comments
 (0)