mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
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.
This commit is contained in:
commit
f58d51b3c0
@ -1185,8 +1185,8 @@ impl clean::FnDecl {
|
|||||||
cx: &Context<'_>,
|
cx: &Context<'_>,
|
||||||
) -> fmt::Result {
|
) -> fmt::Result {
|
||||||
let amp = if f.alternate() { "&" } else { "&" };
|
let amp = if f.alternate() { "&" } else { "&" };
|
||||||
let mut args = String::new();
|
let mut args = Buffer::html();
|
||||||
let mut args_plain = String::new();
|
let mut args_plain = Buffer::new();
|
||||||
for (i, input) in self.inputs.values.iter().enumerate() {
|
for (i, input) in self.inputs.values.iter().enumerate() {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
args.push_str("<br>");
|
args.push_str("<br>");
|
||||||
@ -1199,59 +1199,51 @@ impl clean::FnDecl {
|
|||||||
args_plain.push_str("self");
|
args_plain.push_str("self");
|
||||||
}
|
}
|
||||||
clean::SelfBorrowed(Some(ref lt), mtbl) => {
|
clean::SelfBorrowed(Some(ref lt), mtbl) => {
|
||||||
args.push_str(&format!(
|
write!(args, "{}{} {}self", amp, lt.print(), mtbl.print_with_space());
|
||||||
"{}{} {}self",
|
write!(args_plain, "&{} {}self", lt.print(), mtbl.print_with_space());
|
||||||
amp,
|
|
||||||
lt.print(),
|
|
||||||
mtbl.print_with_space()
|
|
||||||
));
|
|
||||||
args_plain.push_str(&format!(
|
|
||||||
"&{} {}self",
|
|
||||||
lt.print(),
|
|
||||||
mtbl.print_with_space()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
clean::SelfBorrowed(None, mtbl) => {
|
clean::SelfBorrowed(None, mtbl) => {
|
||||||
args.push_str(&format!("{}{}self", amp, mtbl.print_with_space()));
|
write!(args, "{}{}self", amp, mtbl.print_with_space());
|
||||||
args_plain.push_str(&format!("&{}self", mtbl.print_with_space()));
|
write!(args_plain, "&{}self", mtbl.print_with_space());
|
||||||
}
|
}
|
||||||
clean::SelfExplicit(ref typ) => {
|
clean::SelfExplicit(ref typ) => {
|
||||||
if f.alternate() {
|
if f.alternate() {
|
||||||
args.push_str(&format!("self: {:#}", typ.print(cx)));
|
write!(args, "self: {:#}", typ.print(cx));
|
||||||
} else {
|
} else {
|
||||||
args.push_str(&format!("self: {}", typ.print(cx)));
|
write!(args, "self: {}", typ.print(cx));
|
||||||
}
|
}
|
||||||
args_plain.push_str(&format!("self: {:#}", typ.print(cx)));
|
write!(args_plain, "self: {:#}", typ.print(cx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
args.push_str(" <br>");
|
args.push_str(" <br>");
|
||||||
args_plain.push(' ');
|
args_plain.push_str(" ");
|
||||||
}
|
}
|
||||||
if input.is_const {
|
if input.is_const {
|
||||||
args.push_str("const ");
|
args.push_str("const ");
|
||||||
args_plain.push_str("const ");
|
args_plain.push_str("const ");
|
||||||
}
|
}
|
||||||
if !input.name.is_empty() {
|
if !input.name.is_empty() {
|
||||||
args.push_str(&format!("{}: ", input.name));
|
write!(args, "{}: ", input.name);
|
||||||
args_plain.push_str(&format!("{}: ", input.name));
|
write!(args_plain, "{}: ", input.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.alternate() {
|
if f.alternate() {
|
||||||
args.push_str(&format!("{:#}", input.type_.print(cx)));
|
write!(args, "{:#}", input.type_.print(cx));
|
||||||
} else {
|
} else {
|
||||||
args.push_str(&input.type_.print(cx).to_string());
|
write!(args, "{}", input.type_.print(cx));
|
||||||
}
|
}
|
||||||
args_plain.push_str(&format!("{:#}", input.type_.print(cx)));
|
write!(args_plain, "{:#}", input.type_.print(cx));
|
||||||
}
|
}
|
||||||
if i + 1 < self.inputs.values.len() {
|
if i + 1 < self.inputs.values.len() {
|
||||||
args.push(',');
|
args.push_str(",");
|
||||||
args_plain.push(',');
|
args_plain.push_str(",");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut args_plain = format!("({})", args_plain);
|
let mut args_plain = format!("({})", args_plain.into_inner());
|
||||||
|
let mut args = args.into_inner();
|
||||||
|
|
||||||
if self.c_variadic {
|
if self.c_variadic {
|
||||||
args.push_str(",<br> ...");
|
args.push_str(",<br> ...");
|
||||||
|
Loading…
Reference in New Issue
Block a user