Skip to content

Commit 2089bd2

Browse files
committed
doc: Use Vec::push to emulate FILO list
`String.insert_str(0, s)` includes more memcpy and allocations.
1 parent 00eba9d commit 2089bd2

File tree

1 file changed

+11
-7
lines changed
  • src/librustdoc/html/render

1 file changed

+11
-7
lines changed

src/librustdoc/html/render/mod.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ fn render_assoc_items_inner(
12561256
let Some(v) = cache.impls.get(&it) else { return };
12571257
let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none());
12581258
if !non_trait.is_empty() {
1259-
let mut close_tags = String::new();
1259+
let mut close_tags = <Vec<&str>>::with_capacity(1);
12601260
let mut tmp_buf = Buffer::html();
12611261
let (render_mode, id, class_html) = match what {
12621262
AssocItemRender::All => {
@@ -1268,7 +1268,7 @@ fn render_assoc_items_inner(
12681268
cx.derive_id(small_url_encode(format!("deref-methods-{:#}", type_.print(cx))));
12691269
let derived_id = cx.derive_id(&id);
12701270
tmp_buf.write_str("<details class=\"toggle implementors-toggle\" open><summary>");
1271-
close_tags.insert_str(0, "</details>");
1271+
close_tags.push("</details>");
12721272
write_impl_section_heading(
12731273
&mut tmp_buf,
12741274
&format!(
@@ -1312,7 +1312,9 @@ fn render_assoc_items_inner(
13121312
impls_buf.into_inner()
13131313
)
13141314
.unwrap();
1315-
w.write_str(&close_tags).unwrap();
1315+
for tag in close_tags.into_iter().rev() {
1316+
w.write_str(tag).unwrap();
1317+
}
13161318
}
13171319
}
13181320

@@ -1570,7 +1572,7 @@ fn render_impl(
15701572
let cache = &shared.cache;
15711573
let traits = &cache.traits;
15721574
let trait_ = i.trait_did().map(|did| &traits[&did]);
1573-
let mut close_tags = String::new();
1575+
let mut close_tags = <Vec<&str>>::with_capacity(2);
15741576

15751577
// For trait implementations, the `interesting` output contains all methods that have doc
15761578
// comments, and the `boring` output contains all methods that do not. The distinction is
@@ -1858,7 +1860,7 @@ fn render_impl(
18581860
if render_mode == RenderMode::Normal {
18591861
let toggled = !(impl_items.is_empty() && default_impl_items.is_empty());
18601862
if toggled {
1861-
close_tags.insert_str(0, "</details>");
1863+
close_tags.push("</details>");
18621864
write!(
18631865
w,
18641866
"<details class=\"toggle implementors-toggle\"{}>\
@@ -1904,14 +1906,16 @@ fn render_impl(
19041906
}
19051907
if !default_impl_items.is_empty() || !impl_items.is_empty() {
19061908
w.write_str("<div class=\"impl-items\">");
1907-
close_tags.insert_str(0, "</div>");
1909+
close_tags.push("</div>");
19081910
}
19091911
}
19101912
if !default_impl_items.is_empty() || !impl_items.is_empty() {
19111913
w.push_buffer(default_impl_items);
19121914
w.push_buffer(impl_items);
19131915
}
1914-
w.write_str(&close_tags);
1916+
for tag in close_tags.into_iter().rev() {
1917+
w.write_str(tag);
1918+
}
19151919
}
19161920

19171921
// Render the items that appear on the right side of methods, impls, and

0 commit comments

Comments
 (0)