Skip to content

Commit e90149a

Browse files
authored
Rollup merge of rust-lang#109616 - jsha:href-template, r=notriddle
rustdoc: use a template to generate Hrefs Previously, href always returned a string, so each link incurred at least one allocation. We were also using `"../".repeat()`, and `.collect()` into strings to generate part of the paths. This abstracts away those repetitions into a couple of helper structs, ParentDirectories and PathComponents, and puts them together into an `Href` template, which should save some allocations. As a side benefit, I think it makes the logic of constructing links a little clearer. This removes the only call sites for certain methods of UrlPartsBuilder, so it also removes those methods. Also, remove the ItemType return value from `href` and friends; it was basically unused. Part of rust-lang#108868
2 parents ce1073b + ae1a1ef commit e90149a

File tree

7 files changed

+254
-214
lines changed

7 files changed

+254
-214
lines changed

src/librustdoc/clean/types.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ impl Item {
460460
.iter()
461461
.filter_map(|ItemLink { link: s, link_text, page_id: id, ref fragment }| {
462462
debug!(?id);
463-
if let Ok((mut href, ..)) = href(*id, cx) {
463+
if let Ok((href, ..)) = href(*id, cx) {
464+
let mut href = href.render_string();
464465
debug!(?href);
465466
if let Some(ref fragment) = *fragment {
466467
fragment.render(&mut href, cx.tcx())

0 commit comments

Comments
 (0)