From 78365c64c8f4a0eac4699c6bdfeaa4271919c5e0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 29 Aug 2021 12:31:42 +0300 Subject: [PATCH] internal: slightly improve compile times As per style guide, avoid monomorphisations --- crates/ide/src/ssr.rs | 2 +- crates/ide_assists/src/assist_context.rs | 32 +++++++++++++----------- crates/ide_db/src/label.rs | 3 +-- crates/ide_diagnostics/src/lib.rs | 2 +- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/crates/ide/src/ssr.rs b/crates/ide/src/ssr.rs index 57ec802614..6142a0eafd 100644 --- a/crates/ide/src/ssr.rs +++ b/crates/ide/src/ssr.rs @@ -41,7 +41,7 @@ pub(crate) fn ssr_assists( for (label, source_change) in assists.into_iter() { let assist = Assist { id, - label: Label::new(label), + label: Label::new(label.to_string()), group: Some(GroupLabel("Apply SSR".into())), target: comment_range, source_change, diff --git a/crates/ide_assists/src/assist_context.rs b/crates/ide_assists/src/assist_context.rs index 1474505971..0244f5fb29 100644 --- a/crates/ide_assists/src/assist_context.rs +++ b/crates/ide_assists/src/assist_context.rs @@ -131,12 +131,8 @@ impl Assists { target: TextRange, f: impl FnOnce(&mut AssistBuilder), ) -> Option<()> { - if !self.is_allowed(&id) { - return None; - } - let label = Label::new(label.into()); - let assist = Assist { id, label, group: None, target, source_change: None }; - self.add_impl(assist, f) + let mut f = Some(f); + self.add_impl(None, id, label.into(), target, &mut |it| f.take().unwrap()(it)) } pub(crate) fn add_group( @@ -146,26 +142,34 @@ impl Assists { label: impl Into, target: TextRange, f: impl FnOnce(&mut AssistBuilder), + ) -> Option<()> { + let mut f = Some(f); + self.add_impl(Some(group), id, label.into(), target, &mut |it| f.take().unwrap()(it)) + } + + fn add_impl( + &mut self, + group: Option<&GroupLabel>, + id: AssistId, + label: String, + target: TextRange, + f: &mut dyn FnMut(&mut AssistBuilder), ) -> Option<()> { if !self.is_allowed(&id) { return None; } - let label = Label::new(label.into()); - let assist = Assist { id, label, group: Some(group.clone()), target, source_change: None }; - self.add_impl(assist, f) - } - fn add_impl(&mut self, mut assist: Assist, f: impl FnOnce(&mut AssistBuilder)) -> Option<()> { - let source_change = if self.resolve.should_resolve(&assist.id) { + let source_change = if self.resolve.should_resolve(&id) { let mut builder = AssistBuilder::new(self.file); f(&mut builder); Some(builder.finish()) } else { None }; - assist.source_change = source_change; - self.buf.push(assist); + let label = Label::new(label.into()); + let group = group.cloned(); + self.buf.push(Assist { id, label, group, target, source_change }); Some(()) } diff --git a/crates/ide_db/src/label.rs b/crates/ide_db/src/label.rs index 1f1e715c97..4b6d54b5ea 100644 --- a/crates/ide_db/src/label.rs +++ b/crates/ide_db/src/label.rs @@ -29,8 +29,7 @@ impl From