Skip to content

Commit

Permalink
Avoid cloning requirement for unchanged markers (#6116)
Browse files Browse the repository at this point in the history
## Summary

Small optimization.
  • Loading branch information
charliermarsh committed Aug 15, 2024
1 parent 984346f commit 4d13b52
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions crates/uv-resolver/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1524,13 +1524,17 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
return None;
}

Cow::Owned(Requirement {
name: requirement.name.clone(),
extras: requirement.extras.clone(),
source: requirement.source.clone(),
origin: requirement.origin.clone(),
marker
})
if marker == requirement.marker {
requirement
} else {
Cow::Owned(Requirement {
name: requirement.name.clone(),
extras: requirement.extras.clone(),
source: requirement.source.clone(),
origin: requirement.origin.clone(),
marker
})
}
} else {
requirement
};
Expand Down Expand Up @@ -1591,13 +1595,17 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
return None;
}

Cow::Owned(Requirement {
name: constraint.name.clone(),
extras: constraint.extras.clone(),
source: constraint.source.clone(),
origin: constraint.origin.clone(),
marker
})
if marker == constraint.marker {
Cow::Borrowed(constraint)
} else {
Cow::Owned(Requirement {
name: constraint.name.clone(),
extras: constraint.extras.clone(),
source: constraint.source.clone(),
origin: constraint.origin.clone(),
marker
})
}
} else {
// Additionally, if the requirement is `requests ; sys_platform == 'darwin'`
// and the constraint is `requests ; python_version == '3.6'`, the
Expand Down

0 comments on commit 4d13b52

Please sign in to comment.