Skip to content

Commit 7a97b5e

Browse files
committed
Use smallvec crate in pubgrub
1 parent a65790c commit 7a97b5e

File tree

6 files changed

+14
-244
lines changed

6 files changed

+14
-244
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +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"
27-
log = "0.4.22" # for debug logs in tests
25+
# for debug logs in tests
26+
log = "0.4.22"
2827
priority-queue = "2.1.1"
2928
rustc-hash = ">=1.0.0, <3.0.0"
3029
serde = { version = "1.0", features = ["derive"], optional = true }
30+
smallvec = { version = "1.13.2", features = ["union"] }
3131
thiserror = "2.0"
3232
version-ranges = { version = "0.1.0", path = "version-ranges" }
3333

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
@@ -8,10 +8,11 @@ use std::hash::BuildHasherDefault;
88

99
use priority_queue::PriorityQueue;
1010
use rustc_hash::FxHasher;
11+
use smallvec::{smallvec, SmallVec};
1112

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

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

src/internal/small_vec.rs

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

0 commit comments

Comments
 (0)