internal: slightly improve compile times

As per style guide, avoid monomorphisations
This commit is contained in:
Aleksey Kladov 2021-08-29 12:31:42 +03:00
parent bef5e3096e
commit 78365c64c8
4 changed files with 21 additions and 18 deletions

View file

@ -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,

View file

@ -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<String>,
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(())
}

View file

@ -29,8 +29,7 @@ impl From<Label> for String {
}
impl Label {
pub fn new(label: impl Into<String>) -> Label {
let label = label.into();
pub fn new(label: String) -> Label {
assert!(label.starts_with(char::is_uppercase) && !label.ends_with('.'));
Label(label)
}

View file

@ -222,7 +222,7 @@ fn unresolved_fix(id: &'static str, label: &str, target: TextRange) -> Assist {
assert!(!id.contains(' '));
Assist {
id: AssistId(id, AssistKind::QuickFix),
label: Label::new(label),
label: Label::new(label.to_string()),
group: None,
target,
source_change: None,