Skip to content

Commit cd230ad

Browse files
committed
Auto merge of #5118 - Eh2406:more_rc, r=alexcrichton
use more Rc in the part of resolver that gets cloned a lot In a test on #4810 (comment) Before we got to 1700000 ticks in ~(82 to 97) sec After we got to 1700000 ticks in ~(63 to 67) sec
2 parents adadfab + af60861 commit cd230ad

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/cargo/core/resolver/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ struct Context {
344344
warnings: RcList<String>,
345345
}
346346

347-
type Activations = HashMap<String, HashMap<SourceId, Vec<Summary>>>;
347+
type Activations = HashMap<String, HashMap<SourceId, Rc<Vec<Summary>>>>;
348348

349349
/// Builds the list of all packages required to build the first argument.
350350
pub fn resolve(summaries: &[(Summary, Method)],
@@ -1287,15 +1287,17 @@ impl Context {
12871287
.entry(id.name().to_string())
12881288
.or_insert_with(HashMap::new)
12891289
.entry(id.source_id().clone())
1290-
.or_insert_with(Vec::new);
1290+
.or_insert_with(||Rc::new(Vec::new()));
12911291
if !prev.iter().any(|c| c == summary) {
12921292
self.resolve_graph.push(GraphNode::Add(id.clone()));
12931293
if let Some(link) = summary.links() {
12941294
ensure!(self.links.insert(link.to_owned(), id.clone()).is_none(),
12951295
"Attempting to resolve a with more then one crate with the links={}. \n\
12961296
This will not build as is. Consider rebuilding the .lock file.", link);
12971297
}
1298-
prev.push(summary.clone());
1298+
let mut inner: Vec<_> = (**prev).clone();
1299+
inner.push(summary.clone());
1300+
*prev = Rc::new(inner);
12991301
return Ok(false)
13001302
}
13011303
debug!("checking if {} is already activated", summary.package_id());
@@ -1463,7 +1465,7 @@ fn check_cycles(resolve: &Resolve, activations: &Activations)
14631465
-> CargoResult<()> {
14641466
let summaries: HashMap<&PackageId, &Summary> = activations.values()
14651467
.flat_map(|v| v.values())
1466-
.flat_map(|v| v)
1468+
.flat_map(|v| v.iter())
14671469
.map(|s| (s.package_id(), s))
14681470
.collect();
14691471

0 commit comments

Comments
 (0)