Skip to content

Commit d274fba

Browse files
committed
Hoist a workspace membership check out of a loop
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.
1 parent f660b3e commit d274fba

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/cargo/ops/resolve.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ fn register_previous_locks(
517517
if !visited.insert(member.package_id()) {
518518
continue;
519519
}
520+
let is_ws_member = ws.is_member(&member);
520521
for dep in member.dependencies() {
521522
// If this dependency didn't match anything special then we may want
522523
// to poison the source as it may have been added. If this path
@@ -529,11 +530,7 @@ fn register_previous_locks(
529530
// non-workspace member and then simultaneously editing the
530531
// dependency on that crate to enable the feature. For now,
531532
// this bug is better than the always-updating registry though.
532-
if !ws
533-
.members()
534-
.any(|pkg| pkg.package_id() == member.package_id())
535-
&& (dep.is_optional() || !dep.is_transitive())
536-
{
533+
if !is_ws_member && (dep.is_optional() || !dep.is_transitive()) {
537534
continue;
538535
}
539536

0 commit comments

Comments
 (0)