1
Fork 0

rustdoc: Remove Crate.name and instead compute it on-demand

It is not as large as `Crate.src` was, but it's still 8 bytes, and
`clean::Crate` is moved by-value a lot.
This commit is contained in:
Noah Lev 2021-10-28 20:55:02 -07:00
parent 85f8ae8ec4
commit ebe9a11f71
6 changed files with 16 additions and 14 deletions

View file

@ -455,10 +455,10 @@ pub(super) fn write_shared(
let dst = cx.dst.join(&format!("source-files{}.js", cx.shared.resource_suffix));
let make_sources = || {
let (mut all_sources, _krates) =
try_err!(collect(&dst, &krate.name.as_str(), "sourcesIndex"), &dst);
try_err!(collect(&dst, &krate.name(cx.tcx()).as_str(), "sourcesIndex"), &dst);
all_sources.push(format!(
"sourcesIndex[\"{}\"] = {};",
&krate.name,
&krate.name(cx.tcx()),
hierarchy.to_json_string()
));
all_sources.sort();
@ -473,9 +473,10 @@ pub(super) fn write_shared(
// Update the search index and crate list.
let dst = cx.dst.join(&format!("search-index{}.js", cx.shared.resource_suffix));
let (mut all_indexes, mut krates) = try_err!(collect_json(&dst, &krate.name.as_str()), &dst);
let (mut all_indexes, mut krates) =
try_err!(collect_json(&dst, &krate.name(cx.tcx()).as_str()), &dst);
all_indexes.push(search_index);
krates.push(krate.name.to_string());
krates.push(krate.name(cx.tcx()).to_string());
krates.sort();
// Sort the indexes by crate so the file will be generated identically even
@ -599,7 +600,7 @@ pub(super) fn write_shared(
let implementors = format!(
r#"implementors["{}"] = {};"#,
krate.name,
krate.name(cx.tcx()),
serde_json::to_string(&implementors).unwrap()
);
@ -611,7 +612,7 @@ pub(super) fn write_shared(
mydst.push(&format!("{}.{}.js", remote_item_type, remote_path[remote_path.len() - 1]));
let (mut all_implementors, _) =
try_err!(collect(&mydst, &krate.name.as_str(), "implementors"), &mydst);
try_err!(collect(&mydst, &krate.name(cx.tcx()).as_str(), "implementors"), &mydst);
all_implementors.push(implementors);
// Sort the implementors by crate so the file will be generated
// identically even with rustdoc running in parallel.