@@ -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 ( ) ,
@@ -107,7 +106,8 @@ impl<DP: DependencyProvider> State<DP> {
107
106
// to evaluate first the newest incompatibilities.
108
107
let mut conflict_id = None ;
109
108
// We only care about incompatibilities if it contains the current package.
110
- for & incompat_id in self . incompatibilities [ & current_package] . iter ( ) . rev ( ) {
109
+ let idx = current_package. 0 as usize ;
110
+ for & incompat_id in self . incompatibilities [ idx] . iter ( ) . rev ( ) {
111
111
let current_incompat = & mut self . incompatibility_store [ incompat_id] ;
112
112
if self . partial_solution . is_contradicted ( current_incompat) {
113
113
continue ;
@@ -173,7 +173,6 @@ impl<DP: DependencyProvider> State<DP> {
173
173
/// Return the root cause or the terminal incompatibility.
174
174
/// CF <https://github.com/dart-lang/pub/blob/master/doc/solver.md#unit-propagation>
175
175
#[ cold]
176
- #[ allow( clippy:: type_complexity) ]
177
176
fn conflict_resolution (
178
177
& mut self ,
179
178
incompatibility : IncompDpId < DP > ,
@@ -253,6 +252,14 @@ impl<DP: DependencyProvider> State<DP> {
253
252
/// We could collapse them into { foo (1.0.0 ∪ 1.1.0), not bar ^1.0.0 }
254
253
/// without having to check the existence of other versions though.
255
254
fn merge_incompatibility ( & mut self , mut id : IncompDpId < DP > ) {
255
+ fn get_or_default < T > ( v : & mut Vec < Vec < Id < T > > > , package_id : PackageId ) -> & mut Vec < Id < T > > {
256
+ let pkg_idx = package_id. 0 as usize ;
257
+ if pkg_idx + 1 > v. len ( ) {
258
+ v. resize ( pkg_idx + 1 , Vec :: new ( ) ) ;
259
+ }
260
+ & mut v[ pkg_idx]
261
+ }
262
+
256
263
if let Some ( ( pid1, pid2) ) = self . incompatibility_store [ id] . as_dependency ( ) {
257
264
// If we are a dependency, there's a good chance we can be merged with a previous dependency
258
265
let deps_lookup = self . merged_dependencies . entry ( ( pid1, pid2) ) . or_default ( ) ;
@@ -263,10 +270,7 @@ impl<DP: DependencyProvider> State<DP> {
263
270
} ) {
264
271
let new = self . incompatibility_store . alloc ( merged) ;
265
272
for ( package_id, _) in self . incompatibility_store [ new] . iter ( ) {
266
- self . incompatibilities
267
- . entry ( package_id)
268
- . or_default ( )
269
- . retain ( |id| id != past) ;
273
+ get_or_default ( & mut self . incompatibilities , package_id) . retain ( |id| id != past) ;
270
274
}
271
275
* past = new;
272
276
id = new;
@@ -275,13 +279,8 @@ impl<DP: DependencyProvider> State<DP> {
275
279
}
276
280
}
277
281
for ( package_id, term) in self . incompatibility_store [ id] . iter ( ) {
278
- if cfg ! ( debug_assertions) {
279
- assert_ne ! ( term, Term :: any( ) ) ;
280
- }
281
- self . incompatibilities
282
- . entry ( package_id)
283
- . or_default ( )
284
- . push ( id) ;
282
+ debug_assert_ne ! ( term, Term :: any( ) ) ;
283
+ get_or_default ( & mut self . incompatibilities , package_id) . push ( id) ;
285
284
}
286
285
}
287
286
0 commit comments