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() {
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,

View File

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