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