Skip to content

Commit 6535475

Browse files
committed
Auto merge of #5147 - Eh2406:restucture, r=alexcrichton
restructure `Activations` for better clone This builds on the work in #5121 When we last met we had: 5000000 ticks in ~48 sec, 0r 104k ticks/sec This small change brings us to: 5000000 ticks in ~21 sec, 0r 238k ticks/sec Edit: sorry for the large diff only the last commit is new. The rest are from #5121
2 parents 8fde4e3 + 8f9ada8 commit 6535475

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/cargo/core/resolver/mod.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ struct Context {
357357
warnings: RcList<String>,
358358
}
359359

360-
type Activations = HashMap<InternedString, HashMap<SourceId, Rc<Vec<Summary>>>>;
360+
type Activations = HashMap<(InternedString, SourceId), Rc<Vec<Summary>>>;
361361

362362
/// Builds the list of all packages required to build the first argument.
363363
pub fn resolve(summaries: &[(Summary, Method)],
@@ -389,7 +389,6 @@ pub fn resolve(summaries: &[(Summary, Method)],
389389
};
390390

391391
for summary in cx.activations.values()
392-
.flat_map(|v| v.values())
393392
.flat_map(|v| v.iter()) {
394393
let cksum = summary.checksum().map(|s| s.to_string());
395394
resolve.checksums.insert(summary.package_id().clone(), cksum);
@@ -1305,9 +1304,7 @@ impl Context {
13051304
method: &Method) -> CargoResult<bool> {
13061305
let id = summary.package_id();
13071306
let prev = self.activations
1308-
.entry(InternedString::new(id.name()))
1309-
.or_insert_with(HashMap::new)
1310-
.entry(id.source_id().clone())
1307+
.entry((InternedString::new(id.name()), id.source_id().clone()))
13111308
.or_insert_with(||Rc::new(Vec::new()));
13121309
if !prev.iter().any(|c| c == summary) {
13131310
self.resolve_graph.push(GraphNode::Add(id.clone()));
@@ -1368,15 +1365,13 @@ impl Context {
13681365
}
13691366

13701367
fn prev_active(&self, dep: &Dependency) -> &[Summary] {
1371-
self.activations.get(&InternedString::new(dep.name()))
1372-
.and_then(|v| v.get(dep.source_id()))
1368+
self.activations.get(&(InternedString::new(dep.name()), dep.source_id().clone()))
13731369
.map(|v| &v[..])
13741370
.unwrap_or(&[])
13751371
}
13761372

13771373
fn is_active(&self, id: &PackageId) -> bool {
1378-
self.activations.get(&InternedString::new(id.name()))
1379-
.and_then(|v| v.get(id.source_id()))
1374+
self.activations.get(&(InternedString::new(id.name()), id.source_id().clone()))
13801375
.map(|v| v.iter().any(|s| s.package_id() == id))
13811376
.unwrap_or(false)
13821377
}
@@ -1484,7 +1479,6 @@ impl Context {
14841479
fn check_cycles(resolve: &Resolve, activations: &Activations)
14851480
-> CargoResult<()> {
14861481
let summaries: HashMap<&PackageId, &Summary> = activations.values()
1487-
.flat_map(|v| v.values())
14881482
.flat_map(|v| v.iter())
14891483
.map(|s| (s.package_id(), s))
14901484
.collect();

0 commit comments

Comments
 (0)