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:
parent
85f8ae8ec4
commit
ebe9a11f71
6 changed files with 16 additions and 14 deletions
|
@ -116,7 +116,6 @@ impl From<DefId> for ItemId {
|
||||||
/// The crate currently being documented.
|
/// The crate currently being documented.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
crate struct Crate {
|
crate struct Crate {
|
||||||
crate name: Symbol,
|
|
||||||
crate module: Item,
|
crate module: Item,
|
||||||
crate externs: Vec<ExternalCrate>,
|
crate externs: Vec<ExternalCrate>,
|
||||||
crate primitives: ThinVec<(DefId, PrimitiveType)>,
|
crate primitives: ThinVec<(DefId, PrimitiveType)>,
|
||||||
|
@ -130,6 +129,10 @@ crate struct Crate {
|
||||||
rustc_data_structures::static_assert_size!(Crate, 104);
|
rustc_data_structures::static_assert_size!(Crate, 104);
|
||||||
|
|
||||||
impl Crate {
|
impl Crate {
|
||||||
|
crate fn name(&self, tcx: TyCtxt<'_>) -> Symbol {
|
||||||
|
ExternalCrate::LOCAL.name(tcx)
|
||||||
|
}
|
||||||
|
|
||||||
crate fn src(&self, tcx: TyCtxt<'_>) -> FileName {
|
crate fn src(&self, tcx: TyCtxt<'_>) -> FileName {
|
||||||
ExternalCrate::LOCAL.src(tcx)
|
ExternalCrate::LOCAL.src(tcx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,6 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
|
||||||
}
|
}
|
||||||
|
|
||||||
let local_crate = ExternalCrate { crate_num: LOCAL_CRATE };
|
let local_crate = ExternalCrate { crate_num: LOCAL_CRATE };
|
||||||
let name = local_crate.name(cx.tcx);
|
|
||||||
let primitives = local_crate.primitives(cx.tcx);
|
let primitives = local_crate.primitives(cx.tcx);
|
||||||
let keywords = local_crate.keywords(cx.tcx);
|
let keywords = local_crate.keywords(cx.tcx);
|
||||||
{
|
{
|
||||||
|
@ -79,7 +78,6 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
|
||||||
}
|
}
|
||||||
|
|
||||||
Crate {
|
Crate {
|
||||||
name,
|
|
||||||
module,
|
module,
|
||||||
externs,
|
externs,
|
||||||
primitives,
|
primitives,
|
||||||
|
|
|
@ -172,7 +172,7 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
|
||||||
// Collect the index into a string
|
// Collect the index into a string
|
||||||
format!(
|
format!(
|
||||||
r#""{}":{}"#,
|
r#""{}":{}"#,
|
||||||
krate.name,
|
krate.name(tcx),
|
||||||
serde_json::to_string(&CrateData {
|
serde_json::to_string(&CrateData {
|
||||||
doc: crate_doc,
|
doc: crate_doc,
|
||||||
items: crate_items,
|
items: crate_items,
|
||||||
|
|
|
@ -416,14 +416,14 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
|
||||||
let mut playground = None;
|
let mut playground = None;
|
||||||
if let Some(url) = playground_url {
|
if let Some(url) = playground_url {
|
||||||
playground =
|
playground =
|
||||||
Some(markdown::Playground { crate_name: Some(krate.name.to_string()), url });
|
Some(markdown::Playground { crate_name: Some(krate.name(tcx).to_string()), url });
|
||||||
}
|
}
|
||||||
let mut layout = layout::Layout {
|
let mut layout = layout::Layout {
|
||||||
logo: String::new(),
|
logo: String::new(),
|
||||||
favicon: String::new(),
|
favicon: String::new(),
|
||||||
external_html,
|
external_html,
|
||||||
default_settings,
|
default_settings,
|
||||||
krate: krate.name.to_string(),
|
krate: krate.name(tcx).to_string(),
|
||||||
css_file_extension: extension_css,
|
css_file_extension: extension_css,
|
||||||
generate_search_filter,
|
generate_search_filter,
|
||||||
scrape_examples_extension: !call_locations.is_empty(),
|
scrape_examples_extension: !call_locations.is_empty(),
|
||||||
|
@ -444,7 +444,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
|
||||||
}
|
}
|
||||||
(sym::html_playground_url, Some(s)) => {
|
(sym::html_playground_url, Some(s)) => {
|
||||||
playground = Some(markdown::Playground {
|
playground = Some(markdown::Playground {
|
||||||
crate_name: Some(krate.name.to_string()),
|
crate_name: Some(krate.name(tcx).to_string()),
|
||||||
url: s.to_string(),
|
url: s.to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -455,10 +455,10 @@ pub(super) fn write_shared(
|
||||||
let dst = cx.dst.join(&format!("source-files{}.js", cx.shared.resource_suffix));
|
let dst = cx.dst.join(&format!("source-files{}.js", cx.shared.resource_suffix));
|
||||||
let make_sources = || {
|
let make_sources = || {
|
||||||
let (mut all_sources, _krates) =
|
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!(
|
all_sources.push(format!(
|
||||||
"sourcesIndex[\"{}\"] = {};",
|
"sourcesIndex[\"{}\"] = {};",
|
||||||
&krate.name,
|
&krate.name(cx.tcx()),
|
||||||
hierarchy.to_json_string()
|
hierarchy.to_json_string()
|
||||||
));
|
));
|
||||||
all_sources.sort();
|
all_sources.sort();
|
||||||
|
@ -473,9 +473,10 @@ pub(super) fn write_shared(
|
||||||
|
|
||||||
// Update the search index and crate list.
|
// Update the search index and crate list.
|
||||||
let dst = cx.dst.join(&format!("search-index{}.js", cx.shared.resource_suffix));
|
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);
|
all_indexes.push(search_index);
|
||||||
krates.push(krate.name.to_string());
|
krates.push(krate.name(cx.tcx()).to_string());
|
||||||
krates.sort();
|
krates.sort();
|
||||||
|
|
||||||
// Sort the indexes by crate so the file will be generated identically even
|
// 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!(
|
let implementors = format!(
|
||||||
r#"implementors["{}"] = {};"#,
|
r#"implementors["{}"] = {};"#,
|
||||||
krate.name,
|
krate.name(cx.tcx()),
|
||||||
serde_json::to_string(&implementors).unwrap()
|
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]));
|
mydst.push(&format!("{}.{}.js", remote_item_type, remote_path[remote_path.len() - 1]));
|
||||||
|
|
||||||
let (mut all_implementors, _) =
|
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);
|
all_implementors.push(implementors);
|
||||||
// Sort the implementors by crate so the file will be generated
|
// Sort the implementors by crate so the file will be generated
|
||||||
// identically even with rustdoc running in parallel.
|
// identically even with rustdoc running in parallel.
|
||||||
|
|
|
@ -18,7 +18,7 @@ use std::path::{Component, Path, PathBuf};
|
||||||
|
|
||||||
crate fn render(cx: &mut Context<'_>, krate: clean::Crate) -> Result<clean::Crate, Error> {
|
crate fn render(cx: &mut Context<'_>, krate: clean::Crate) -> Result<clean::Crate, Error> {
|
||||||
info!("emitting source files");
|
info!("emitting source files");
|
||||||
let dst = cx.dst.join("src").join(&*krate.name.as_str());
|
let dst = cx.dst.join("src").join(&*krate.name(cx.tcx()).as_str());
|
||||||
cx.shared.ensure_dir(&dst)?;
|
cx.shared.ensure_dir(&dst)?;
|
||||||
let mut folder = SourceCollector { dst, cx, emitted_local_sources: FxHashSet::default() };
|
let mut folder = SourceCollector { dst, cx, emitted_local_sources: FxHashSet::default() };
|
||||||
Ok(folder.fold_crate(krate))
|
Ok(folder.fold_crate(krate))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue