Skip to content

Commit 41de685

Browse files
committed
rustdoc: write directly to buffer in inner_full_print
This change avoids several temporary allocations for every argument.
1 parent c651ba8 commit 41de685

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
@@ -1171,8 +1171,8 @@ impl clean::FnDecl {
11711171
cx: &Context<'_>,
11721172
) -> fmt::Result {
11731173
let amp = if f.alternate() { "&" } else { "&amp;" };
1174-
let mut args = String::new();
1175-
let mut args_plain = String::new();
1174+
let mut args = Buffer::html();
1175+
let mut args_plain = Buffer::new();
11761176
for (i, input) in self.inputs.values.iter().enumerate() {
11771177
if i == 0 {
11781178
args.push_str("<br>");
@@ -1185,59 +1185,51 @@ impl clean::FnDecl {
11851185
args_plain.push_str("self");
11861186
}
11871187
clean::SelfBorrowed(Some(ref lt), mtbl) => {
1188-
args.push_str(&format!(
1189-
"{}{} {}self",
1190-
amp,
1191-
lt.print(),
1192-
mtbl.print_with_space()
1193-
));
1194-
args_plain.push_str(&format!(
1195-
"&{} {}self",
1196-
lt.print(),
1197-
mtbl.print_with_space()
1198-
));
1188+
write!(args, "{}{} {}self", amp, lt.print(), mtbl.print_with_space());
1189+
write!(args_plain, "&{} {}self", lt.print(), mtbl.print_with_space());
11991190
}
12001191
clean::SelfBorrowed(None, mtbl) => {
1201-
args.push_str(&format!("{}{}self", amp, mtbl.print_with_space()));
1202-
args_plain.push_str(&format!("&{}self", mtbl.print_with_space()));
1192+
write!(args, "{}{}self", amp, mtbl.print_with_space());
1193+
write!(args_plain, "&{}self", mtbl.print_with_space());
12031194
}
12041195
clean::SelfExplicit(ref typ) => {
12051196
if f.alternate() {
1206-
args.push_str(&format!("self: {:#}", typ.print(cx)));
1197+
write!(args, "self: {:#}", typ.print(cx));
12071198
} else {
1208-
args.push_str(&format!("self: {}", typ.print(cx)));
1199+
write!(args, "self: {}", typ.print(cx));
12091200
}
1210-
args_plain.push_str(&format!("self: {:#}", typ.print(cx)));
1201+
write!(args_plain, "self: {:#}", typ.print(cx));
12111202
}
12121203
}
12131204
} else {
12141205
if i > 0 {
12151206
args.push_str(" <br>");
1216-
args_plain.push(' ');
1207+
args_plain.push_str(" ");
12171208
}
12181209
if input.is_const {
12191210
args.push_str("const ");
12201211
args_plain.push_str("const ");
12211212
}
12221213
if !input.name.is_empty() {
1223-
args.push_str(&format!("{}: ", input.name));
1224-
args_plain.push_str(&format!("{}: ", input.name));
1214+
write!(args, "{}: ", input.name);
1215+
write!(args_plain, "{}: ", input.name);
12251216
}
12261217

12271218
if f.alternate() {
1228-
args.push_str(&format!("{:#}", input.type_.print(cx)));
1219+
write!(args, "{:#}", input.type_.print(cx));
12291220
} else {
1230-
args.push_str(&input.type_.print(cx).to_string());
1221+
write!(args, "{}", input.type_.print(cx));
12311222
}
1232-
args_plain.push_str(&format!("{:#}", input.type_.print(cx)));
1223+
write!(args_plain, "{:#}", input.type_.print(cx));
12331224
}
12341225
if i + 1 < self.inputs.values.len() {
1235-
args.push(',');
1236-
args_plain.push(',');
1226+
args.push_str(",");
1227+
args_plain.push_str(",");
12371228
}
12381229
}
12391230

1240-
let mut args_plain = format!("({})", args_plain);
1231+
let mut args_plain = format!("({})", args_plain.into_inner());
1232+
let mut args = args.into_inner();
12411233

12421234
if self.c_variadic {
12431235
args.push_str(",<br> ...");

0 commit comments

Comments
 (0)