Skip to content

Commit cda6efe

Browse files
committed
generate_macro_def_id_path: don't eagerly stringify Symbols
1 parent 4e1258c commit cda6efe

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/librustdoc/html/format.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ fn generate_macro_def_id_path(
569569
root_path: Option<&str>,
570570
) -> Result<(String, ItemType, Vec<Symbol>), HrefError> {
571571
let tcx = cx.shared.tcx;
572-
let crate_name = tcx.crate_name(def_id.krate).to_string();
572+
let crate_name = tcx.crate_name(def_id.krate);
573573
let cache = cx.cache();
574574

575575
let fqp: Vec<Symbol> = tcx
@@ -584,7 +584,7 @@ fn generate_macro_def_id_path(
584584
}
585585
})
586586
.collect();
587-
let mut relative = fqp.iter().map(|elem| elem.to_string());
587+
let mut relative = fqp.iter().copied();
588588
let cstore = CStore::from_tcx(tcx);
589589
// We need this to prevent a `panic` when this function is used from intra doc links...
590590
if !cstore.has_crate_data(def_id.krate) {
@@ -602,9 +602,9 @@ fn generate_macro_def_id_path(
602602
};
603603

604604
let mut path = if is_macro_2 {
605-
once(crate_name.clone()).chain(relative).collect()
605+
once(crate_name).chain(relative).collect()
606606
} else {
607-
vec![crate_name.clone(), relative.next_back().unwrap()]
607+
vec![crate_name, relative.next_back().unwrap()]
608608
};
609609
if path.len() < 2 {
610610
// The minimum we can have is the crate name followed by the macro name. If shorter, then
@@ -614,17 +614,22 @@ fn generate_macro_def_id_path(
614614
}
615615

616616
if let Some(last) = path.last_mut() {
617-
*last = format!("macro.{}.html", last);
617+
*last = Symbol::intern(&format!("macro.{}.html", last.as_str()));
618618
}
619619

620620
let url = match cache.extern_locations[&def_id.krate] {
621621
ExternalLocation::Remote(ref s) => {
622622
// `ExternalLocation::Remote` always end with a `/`.
623-
format!("{}{}", s, path.join("/"))
623+
format!("{}{}", s, path.iter().map(|p| p.as_str()).join("/"))
624624
}
625625
ExternalLocation::Local => {
626626
// `root_path` always end with a `/`.
627-
format!("{}{}/{}", root_path.unwrap_or(""), crate_name, path.join("/"))
627+
format!(
628+
"{}{}/{}",
629+
root_path.unwrap_or(""),
630+
crate_name,
631+
path.iter().map(|p| p.as_str()).join("/")
632+
)
628633
}
629634
ExternalLocation::Unknown => {
630635
debug!("crate {} not in cache when linkifying macros", crate_name);

0 commit comments

Comments
 (0)