refactor: iterator instead of extra allocation for registering patches

This commit is contained in:
Weihang Lo 2024-05-15 08:52:46 -04:00
parent a6230e348b
commit 178bde773b
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
2 changed files with 4 additions and 7 deletions

View File

@ -205,7 +205,7 @@ impl Resolve {
self.graph.path_to_top(pkg)
}
pub fn register_used_patches(&mut self, patches: &[Summary]) {
pub fn register_used_patches<'a>(&mut self, patches: impl Iterator<Item = &'a Summary>) {
for summary in patches {
if !self.graph.contains(&summary.package_id()) {
self.unused_patches.push(summary.package_id())

View File

@ -412,12 +412,9 @@ pub fn resolve_with_previous<'gctx>(
ResolveVersion::with_rust_version(ws.rust_version()),
Some(ws.gctx()),
)?;
let patches: Vec<_> = registry
.patches()
.values()
.flat_map(|v| v.iter().cloned())
.collect();
resolved.register_used_patches(&patches[..]);
let patches = registry.patches().values().flat_map(|v| v.iter());
resolved.register_used_patches(patches);
if register_patches && !resolved.unused_patches().is_empty() {
emit_warnings_of_unused_patches(ws, &resolved, registry)?;