Auto merge of #90391 - camelid:crate-size, r=jyn514

rustdoc: Compute some fields of `clean::Crate` on-demand to reduce size

`clean::Crate` is frequently moved by-value -- for example, in `DocFolder`
implementations -- so reducing its size should improve performance.

This PR reduces the size of `clean::Crate` from 168 bytes to 104 bytes.

r? `@jyn514`
This commit is contained in:
bors
2021-10-31 05:52:42 +00:00
6 changed files with 31 additions and 20 deletions

View File

@@ -408,7 +408,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
..
} = options;
let src_root = match krate.src {
let src_root = match krate.src(tcx) {
FileName::Real(ref p) => match p.local_path_if_available().parent() {
Some(p) => p.to_path_buf(),
None => PathBuf::new(),
@@ -419,14 +419,14 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
let mut playground = None;
if let Some(url) = playground_url {
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 {
logo: String::new(),
favicon: String::new(),
external_html,
default_settings,
krate: krate.name.to_string(),
krate: krate.name(tcx).to_string(),
css_file_extension: extension_css,
generate_search_filter,
scrape_examples_extension: !call_locations.is_empty(),
@@ -447,7 +447,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
}
(sym::html_playground_url, Some(s)) => {
playground = Some(markdown::Playground {
crate_name: Some(krate.name.to_string()),
crate_name: Some(krate.name(tcx).to_string()),
url: s.to_string(),
});
}