Skip to content

Commit

Permalink
Hoist a workspace membership check out of a loop
Browse files Browse the repository at this point in the history
This commit moves a linear scan which happens once-per-each-dependency
to an O(1) lookup which happens only once for each package. This removes
another 30ms or so from a null build in Servo.
  • Loading branch information
alexcrichton committed Apr 22, 2019
1 parent f660b3e commit d274fba
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ fn register_previous_locks(
if !visited.insert(member.package_id()) {
continue;
}
let is_ws_member = ws.is_member(&member);
for dep in member.dependencies() {
// If this dependency didn't match anything special then we may want
// to poison the source as it may have been added. If this path
Expand All @@ -529,11 +530,7 @@ fn register_previous_locks(
// non-workspace member and then simultaneously editing the
// dependency on that crate to enable the feature. For now,
// this bug is better than the always-updating registry though.
if !ws
.members()
.any(|pkg| pkg.package_id() == member.package_id())
&& (dep.is_optional() || !dep.is_transitive())
{
if !is_ws_member && (dep.is_optional() || !dep.is_transitive()) {
continue;
}

Expand Down

0 comments on commit d274fba

Please sign in to comment.