10071: internal: slightly improve compile times r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2021-08-29 09:54:33 +00:00 committed by GitHub
commit 35d98070d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 19 deletions

View file

@ -41,7 +41,7 @@ pub(crate) fn ssr_assists(
for (label, source_change) in assists.into_iter() { for (label, source_change) in assists.into_iter() {
let assist = Assist { let assist = Assist {
id, id,
label: Label::new(label), label: Label::new(label.to_string()),
group: Some(GroupLabel("Apply SSR".into())), group: Some(GroupLabel("Apply SSR".into())),
target: comment_range, target: comment_range,
source_change, source_change,

View file

@ -131,12 +131,8 @@ impl Assists {
target: TextRange, target: TextRange,
f: impl FnOnce(&mut AssistBuilder), f: impl FnOnce(&mut AssistBuilder),
) -> Option<()> { ) -> Option<()> {
if !self.is_allowed(&id) { let mut f = Some(f);
return None; self.add_impl(None, id, label.into(), target, &mut |it| f.take().unwrap()(it))
}
let label = Label::new(label.into());
let assist = Assist { id, label, group: None, target, source_change: None };
self.add_impl(assist, f)
} }
pub(crate) fn add_group( pub(crate) fn add_group(
@ -146,26 +142,34 @@ impl Assists {
label: impl Into<String>, label: impl Into<String>,
target: TextRange, target: TextRange,
f: impl FnOnce(&mut AssistBuilder), 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<()> { ) -> Option<()> {
if !self.is_allowed(&id) { if !self.is_allowed(&id) {
return None; 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(&id) {
let source_change = if self.resolve.should_resolve(&assist.id) {
let mut builder = AssistBuilder::new(self.file); let mut builder = AssistBuilder::new(self.file);
f(&mut builder); f(&mut builder);
Some(builder.finish()) Some(builder.finish())
} else { } else {
None 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(()) Some(())
} }

View file

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

View file

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

View file

@ -99,7 +99,7 @@ mod tests {
}; };
let json = serde_json::to_string(&task).unwrap(); let json = serde_json::to_string(&task).unwrap();
println!("{}", json); // println!("{}", json);
let back: ExpansionTask = serde_json::from_str(&json).unwrap(); let back: ExpansionTask = serde_json::from_str(&json).unwrap();
assert_eq!(tt, back.macro_body.to_subtree()); assert_eq!(tt, back.macro_body.to_subtree());