Skip to content

Commit f443ba0

Browse files
authored
Merge pull request #19376 from Veykril/push-ultzutkwqupt
minor: Remove unnecessary allocations in `function::params_display`
2 parents 8b5816b + 6a63787 commit f443ba0

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

crates/ide-completion/src/render/function.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,9 @@ fn detail(ctx: &CompletionContext<'_>, func: hir::Function) -> String {
320320
format_to!(detail, "unsafe ");
321321
}
322322

323-
format_to!(detail, "fn({})", params_display(ctx, func));
323+
detail.push_str("fn(");
324+
params_display(ctx, &mut detail, func);
325+
detail.push(')');
324326
if !ret_ty.is_unit() {
325327
format_to!(detail, " -> {}", ret_ty.display(ctx.db, ctx.display_target));
326328
}
@@ -342,31 +344,29 @@ fn detail_full(ctx: &CompletionContext<'_>, func: hir::Function) -> String {
342344
detail
343345
}
344346

345-
fn params_display(ctx: &CompletionContext<'_>, func: hir::Function) -> String {
346-
let mut params = if let Some(self_param) = func.self_param(ctx.db) {
347+
fn params_display(ctx: &CompletionContext<'_>, detail: &mut String, func: hir::Function) {
348+
if let Some(self_param) = func.self_param(ctx.db) {
349+
format_to!(detail, "{}", self_param.display(ctx.db, ctx.display_target));
347350
let assoc_fn_params = func.assoc_fn_params(ctx.db);
348351
let params = assoc_fn_params
349352
.iter()
350353
.skip(1) // skip the self param because we are manually handling that
351354
.map(|p| p.ty().display(ctx.db, ctx.display_target));
352-
format!(
353-
"{}{}",
354-
self_param.display(ctx.db, ctx.display_target),
355-
params.format_with("", |display, f| {
356-
f(&", ")?;
357-
f(&display)
358-
})
359-
)
355+
for param in params {
356+
format_to!(detail, ", {}", param);
357+
}
360358
} else {
361359
let assoc_fn_params = func.assoc_fn_params(ctx.db);
362-
assoc_fn_params.iter().map(|p| p.ty().display(ctx.db, ctx.display_target)).join(", ")
363-
};
360+
format_to!(
361+
detail,
362+
"{}",
363+
assoc_fn_params.iter().map(|p| p.ty().display(ctx.db, ctx.display_target)).format(", ")
364+
);
365+
}
364366

365367
if func.is_varargs(ctx.db) {
366-
params.push_str(", ...");
368+
detail.push_str(", ...");
367369
}
368-
369-
params
370370
}
371371

372372
fn params(

0 commit comments

Comments
 (0)