From 383635a13e336c35c2c41d412e4452ecd86e5cf2 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 19 May 2021 19:05:03 +0200 Subject: Rewrite `resolve_imports` to use an iterator This allows reusing the original vector's allocation --- crates/hir_def/src/nameres/collector.rs | 42 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 24ba7dbe9..66d9396aa 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -561,26 +561,30 @@ impl DefCollector<'_> { fn resolve_imports(&mut self) -> ReachedFixedPoint { let mut res = ReachedFixedPoint::Yes; let imports = std::mem::replace(&mut self.unresolved_imports, Vec::new()); - for mut directive in imports { - directive.status = self.resolve_import(directive.module_id, &directive.import); - match directive.status { - PartialResolvedImport::Indeterminate(_) => { - self.record_resolved_import(&directive); - // FIXME: For avoid performance regression, - // we consider an imported resolved if it is indeterminate (i.e not all namespace resolved) - self.resolved_imports.push(directive); - res = ReachedFixedPoint::No; - } - PartialResolvedImport::Resolved(_) => { - self.record_resolved_import(&directive); - self.resolved_imports.push(directive); - res = ReachedFixedPoint::No; - } - PartialResolvedImport::Unresolved => { - self.unresolved_imports.push(directive); + let imports = imports + .into_iter() + .filter_map(|mut directive| { + directive.status = self.resolve_import(directive.module_id, &directive.import); + match directive.status { + PartialResolvedImport::Indeterminate(_) => { + self.record_resolved_import(&directive); + // FIXME: For avoid performance regression, + // we consider an imported resolved if it is indeterminate (i.e not all namespace resolved) + self.resolved_imports.push(directive); + res = ReachedFixedPoint::No; + None + } + PartialResolvedImport::Resolved(_) => { + self.record_resolved_import(&directive); + self.resolved_imports.push(directive); + res = ReachedFixedPoint::No; + None + } + PartialResolvedImport::Unresolved => Some(directive), } - } - } + }) + .collect(); + self.unresolved_imports = imports; res } -- cgit v1.2.3