Skip to content

Commit f58d51b

Browse files
committed
Auto merge of #94304 - notriddle:notriddle/buffer-args, r=CraftSpider
rustdoc: write directly to buffer in `inner_full_print` This change avoids several temporary allocations for every argument.
2 parents 8756ed2 + 41de685 commit f58d51b

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

Diff for: src/librustdoc/html/format.rs

+19-27
Original file line numberDiff line numberDiff line change
@@ -1185,8 +1185,8 @@ impl clean::FnDecl {
11851185
cx: &Context<'_>,
11861186
) -> fmt::Result {
11871187
let amp = if f.alternate() { "&" } else { "&amp;" };
1188-
let mut args = String::new();
1189-
let mut args_plain = String::new();
1188+
let mut args = Buffer::html();
1189+
let mut args_plain = Buffer::new();
11901190
for (i, input) in self.inputs.values.iter().enumerate() {
11911191
if i == 0 {
11921192
args.push_str("<br>");
@@ -1199,59 +1199,51 @@ impl clean::FnDecl {
11991199
args_plain.push_str("self");
12001200
}
12011201
clean::SelfBorrowed(Some(ref lt), mtbl) => {
1202-
args.push_str(&format!(
1203-
"{}{} {}self",
1204-
amp,
1205-
lt.print(),
1206-
mtbl.print_with_space()
1207-
));
1208-
args_plain.push_str(&format!(
1209-
"&{} {}self",
1210-
lt.print(),
1211-
mtbl.print_with_space()
1212-
));
1202+
write!(args, "{}{} {}self", amp, lt.print(), mtbl.print_with_space());
1203+
write!(args_plain, "&{} {}self", lt.print(), mtbl.print_with_space());
12131204
}
12141205
clean::SelfBorrowed(None, mtbl) => {
1215-
args.push_str(&format!("{}{}self", amp, mtbl.print_with_space()));
1216-
args_plain.push_str(&format!("&{}self", mtbl.print_with_space()));
1206+
write!(args, "{}{}self", amp, mtbl.print_with_space());
1207+
write!(args_plain, "&{}self", mtbl.print_with_space());
12171208
}
12181209
clean::SelfExplicit(ref typ) => {
12191210
if f.alternate() {
1220-
args.push_str(&format!("self: {:#}", typ.print(cx)));
1211+
write!(args, "self: {:#}", typ.print(cx));
12211212
} else {
1222-
args.push_str(&format!("self: {}", typ.print(cx)));
1213+
write!(args, "self: {}", typ.print(cx));
12231214
}
1224-
args_plain.push_str(&format!("self: {:#}", typ.print(cx)));
1215+
write!(args_plain, "self: {:#}", typ.print(cx));
12251216
}
12261217
}
12271218
} else {
12281219
if i > 0 {
12291220
args.push_str(" <br>");
1230-
args_plain.push(' ');
1221+
args_plain.push_str(" ");
12311222
}
12321223
if input.is_const {
12331224
args.push_str("const ");
12341225
args_plain.push_str("const ");
12351226
}
12361227
if !input.name.is_empty() {
1237-
args.push_str(&format!("{}: ", input.name));
1238-
args_plain.push_str(&format!("{}: ", input.name));
1228+
write!(args, "{}: ", input.name);
1229+
write!(args_plain, "{}: ", input.name);
12391230
}
12401231

12411232
if f.alternate() {
1242-
args.push_str(&format!("{:#}", input.type_.print(cx)));
1233+
write!(args, "{:#}", input.type_.print(cx));
12431234
} else {
1244-
args.push_str(&input.type_.print(cx).to_string());
1235+
write!(args, "{}", input.type_.print(cx));
12451236
}
1246-
args_plain.push_str(&format!("{:#}", input.type_.print(cx)));
1237+
write!(args_plain, "{:#}", input.type_.print(cx));
12471238
}
12481239
if i + 1 < self.inputs.values.len() {
1249-
args.push(',');
1250-
args_plain.push(',');
1240+
args.push_str(",");
1241+
args_plain.push_str(",");
12511242
}
12521243
}
12531244

1254-
let mut args_plain = format!("({})", args_plain);
1245+
let mut args_plain = format!("({})", args_plain.into_inner());
1246+
let mut args = args.into_inner();
12551247

12561248
if self.c_variadic {
12571249
args.push_str(",<br> ...");

0 commit comments

Comments
 (0)