Skip to content

Commit 35d9807

Browse files
bors[bot]matklad
andauthored
Merge #10071
10071: internal: slightly improve compile times r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 7c7a41c + 78365c6 commit 35d9807

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

crates/ide/src/ssr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub(crate) fn ssr_assists(
4141
for (label, source_change) in assists.into_iter() {
4242
let assist = Assist {
4343
id,
44-
label: Label::new(label),
44+
label: Label::new(label.to_string()),
4545
group: Some(GroupLabel("Apply SSR".into())),
4646
target: comment_range,
4747
source_change,

crates/ide_assists/src/assist_context.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,8 @@ impl Assists {
131131
target: TextRange,
132132
f: impl FnOnce(&mut AssistBuilder),
133133
) -> Option<()> {
134-
if !self.is_allowed(&id) {
135-
return None;
136-
}
137-
let label = Label::new(label.into());
138-
let assist = Assist { id, label, group: None, target, source_change: None };
139-
self.add_impl(assist, f)
134+
let mut f = Some(f);
135+
self.add_impl(None, id, label.into(), target, &mut |it| f.take().unwrap()(it))
140136
}
141137

142138
pub(crate) fn add_group(
@@ -146,26 +142,34 @@ impl Assists {
146142
label: impl Into<String>,
147143
target: TextRange,
148144
f: impl FnOnce(&mut AssistBuilder),
145+
) -> Option<()> {
146+
let mut f = Some(f);
147+
self.add_impl(Some(group), id, label.into(), target, &mut |it| f.take().unwrap()(it))
148+
}
149+
150+
fn add_impl(
151+
&mut self,
152+
group: Option<&GroupLabel>,
153+
id: AssistId,
154+
label: String,
155+
target: TextRange,
156+
f: &mut dyn FnMut(&mut AssistBuilder),
149157
) -> Option<()> {
150158
if !self.is_allowed(&id) {
151159
return None;
152160
}
153-
let label = Label::new(label.into());
154-
let assist = Assist { id, label, group: Some(group.clone()), target, source_change: None };
155-
self.add_impl(assist, f)
156-
}
157161

158-
fn add_impl(&mut self, mut assist: Assist, f: impl FnOnce(&mut AssistBuilder)) -> Option<()> {
159-
let source_change = if self.resolve.should_resolve(&assist.id) {
162+
let source_change = if self.resolve.should_resolve(&id) {
160163
let mut builder = AssistBuilder::new(self.file);
161164
f(&mut builder);
162165
Some(builder.finish())
163166
} else {
164167
None
165168
};
166-
assist.source_change = source_change;
167169

168-
self.buf.push(assist);
170+
let label = Label::new(label.into());
171+
let group = group.cloned();
172+
self.buf.push(Assist { id, label, group, target, source_change });
169173
Some(())
170174
}
171175

crates/ide_db/src/label.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ impl From<Label> for String {
2929
}
3030

3131
impl Label {
32-
pub fn new(label: impl Into<String>) -> Label {
33-
let label = label.into();
32+
pub fn new(label: String) -> Label {
3433
assert!(label.starts_with(char::is_uppercase) && !label.ends_with('.'));
3534
Label(label)
3635
}

crates/ide_diagnostics/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ fn unresolved_fix(id: &'static str, label: &str, target: TextRange) -> Assist {
222222
assert!(!id.contains(' '));
223223
Assist {
224224
id: AssistId(id, AssistKind::QuickFix),
225-
label: Label::new(label),
225+
label: Label::new(label.to_string()),
226226
group: None,
227227
target,
228228
source_change: None,

crates/proc_macro_api/src/rpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ mod tests {
9999
};
100100

101101
let json = serde_json::to_string(&task).unwrap();
102-
println!("{}", json);
102+
// println!("{}", json);
103103
let back: ExpansionTask = serde_json::from_str(&json).unwrap();
104104

105105
assert_eq!(tt, back.macro_body.to_subtree());

0 commit comments

Comments
 (0)