@@ -9,7 +9,7 @@ use smallvec::SmallVec;
9
9
10
10
use crate :: {
11
11
internal:: {
12
- Arena , DecisionLevel , IncompDpId , Incompatibility , PartialSolution , Relation ,
12
+ Arena , DecisionLevel , Id , IncompDpId , Incompatibility , PartialSolution , Relation ,
13
13
SatisfierSearch ,
14
14
} ,
15
15
DependencyProvider , DerivationTree , Map , Package , PackageArena , Set , Term , Version , VersionSet ,
@@ -21,12 +21,10 @@ pub(crate) struct State<DP: DependencyProvider> {
21
21
root_package : Package ,
22
22
root_version : Version ,
23
23
24
- #[ allow( clippy:: type_complexity) ]
25
- incompatibilities : Map < Package , Vec < IncompDpId < DP > > > ,
24
+ incompatibilities : Vec < Vec < IncompDpId < DP > > > ,
26
25
27
26
/// All incompatibilities expressing dependencies,
28
27
/// with common dependents merged.
29
- #[ allow( clippy:: type_complexity) ]
30
28
merged_dependencies : Map < ( Package , Package ) , SmallVec < [ IncompDpId < DP > ; 4 ] > > ,
31
29
32
30
/// Partial solution.
@@ -48,13 +46,14 @@ impl<DP: DependencyProvider> State<DP> {
48
46
let mut incompatibility_store = Arena :: new ( ) ;
49
47
let not_root_id =
50
48
incompatibility_store. alloc ( Incompatibility :: not_root ( root_package, root_version) ) ;
51
- let mut incompatibilities = Map :: default ( ) ;
52
- incompatibilities. insert ( root_package, vec ! [ not_root_id] ) ;
49
+ let root_package_idx = root_package. 0 as usize ;
50
+ let mut incompatibilities = vec ! [ vec![ ] ; root_package_idx + 1 ] ;
51
+ incompatibilities[ root_package_idx] . push ( not_root_id) ;
53
52
Self {
54
53
root_package,
55
54
root_version,
56
55
incompatibilities,
57
- partial_solution : PartialSolution :: empty ( ) ,
56
+ partial_solution : PartialSolution :: empty ( root_package ) ,
58
57
incompatibility_store,
59
58
unit_propagation_buffer : Vec :: new ( ) ,
60
59
merged_dependencies : Map :: default ( ) ,
@@ -102,7 +101,8 @@ impl<DP: DependencyProvider> State<DP> {
102
101
// to evaluate first the newest incompatibilities.
103
102
let mut conflict_id = None ;
104
103
// We only care about incompatibilities if it contains the current package.
105
- for & incompat_id in self . incompatibilities [ & current_package] . iter ( ) . rev ( ) {
104
+ let idx = current_package. 0 as usize ;
105
+ for & incompat_id in self . incompatibilities [ idx] . iter ( ) . rev ( ) {
106
106
let current_incompat = & mut self . incompatibility_store [ incompat_id] ;
107
107
if self . partial_solution . is_contradicted ( current_incompat) {
108
108
continue ;
@@ -167,7 +167,6 @@ impl<DP: DependencyProvider> State<DP> {
167
167
168
168
/// Return the root cause or the terminal incompatibility.
169
169
/// CF <https://github.com/dart-lang/pub/blob/master/doc/solver.md#unit-propagation>
170
- #[ allow( clippy:: type_complexity) ]
171
170
fn conflict_resolution (
172
171
& mut self ,
173
172
incompatibility : IncompDpId < DP > ,
@@ -247,6 +246,14 @@ impl<DP: DependencyProvider> State<DP> {
247
246
/// We could collapse them into { foo (1.0.0 ∪ 1.1.0), not bar ^1.0.0 }
248
247
/// without having to check the existence of other versions though.
249
248
fn merge_incompatibility ( & mut self , mut id : IncompDpId < DP > ) {
249
+ fn get_or_default < T > ( v : & mut Vec < Vec < Id < T > > > , pkg : Package ) -> & mut Vec < Id < T > > {
250
+ let pkg_idx = pkg. 0 as usize ;
251
+ if pkg_idx + 1 > v. len ( ) {
252
+ v. resize ( pkg_idx + 1 , Vec :: new ( ) ) ;
253
+ }
254
+ & mut v[ pkg_idx]
255
+ }
256
+
250
257
if let Some ( ( p1, p2) ) = self . incompatibility_store [ id] . as_dependency ( ) {
251
258
// If we are a dependency, there's a good chance we can be merged with a previous dependency
252
259
let deps_lookup = self . merged_dependencies . entry ( ( p1, p2) ) . or_default ( ) ;
@@ -257,10 +264,7 @@ impl<DP: DependencyProvider> State<DP> {
257
264
} ) {
258
265
let new = self . incompatibility_store . alloc ( merged) ;
259
266
for ( pkg, _) in self . incompatibility_store [ new] . iter ( ) {
260
- self . incompatibilities
261
- . entry ( pkg)
262
- . or_default ( )
263
- . retain ( |id| id != past) ;
267
+ get_or_default ( & mut self . incompatibilities , pkg) . retain ( |id| id != past) ;
264
268
}
265
269
* past = new;
266
270
id = new;
@@ -269,10 +273,8 @@ impl<DP: DependencyProvider> State<DP> {
269
273
}
270
274
}
271
275
for ( pkg, term) in self . incompatibility_store [ id] . iter ( ) {
272
- if cfg ! ( debug_assertions) {
273
- assert_ne ! ( term, Term :: any( ) ) ;
274
- }
275
- self . incompatibilities . entry ( pkg) . or_default ( ) . push ( id) ;
276
+ debug_assert_ne ! ( term, Term :: any( ) ) ;
277
+ get_or_default ( & mut self . incompatibilities , pkg) . push ( id) ;
276
278
}
277
279
}
278
280
0 commit comments