Skip to content

Commit 5873fe8

Browse files
Rollup merge of rust-lang#80047 - jyn514:more-symbols, r=GuillaumeGomez
Use more symbols in rustdoc Builds on rust-lang#80044 and should not be merged before. I want to test if this is actually faster before merging it, there was a lot of `to_string()` calls so I'm not sure it will actually help. That means I have to wait for 80044 to get merged before running perf. r? `@ghost`
2 parents 1f5d8de + 7ee8e18 commit 5873fe8

File tree

9 files changed

+29
-30
lines changed

9 files changed

+29
-30
lines changed

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl Clean<ExternalCrate> for CrateNum {
207207
};
208208

209209
ExternalCrate {
210-
name: cx.tcx.crate_name(*self).to_string(),
210+
name: cx.tcx.crate_name(*self),
211211
src: krate_src,
212212
attrs: cx.tcx.get_attrs(root).clean(cx),
213213
primitives,

src/librustdoc/clean/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ thread_local!(crate static MAX_DEF_ID: RefCell<FxHashMap<CrateNum, DefId>> = Def
5151

5252
#[derive(Clone, Debug)]
5353
crate struct Crate {
54-
crate name: String,
54+
crate name: Symbol,
5555
crate version: Option<String>,
5656
crate src: FileName,
5757
crate module: Option<Item>,
@@ -66,7 +66,7 @@ crate struct Crate {
6666

6767
#[derive(Clone, Debug)]
6868
crate struct ExternalCrate {
69-
crate name: String,
69+
crate name: Symbol,
7070
crate src: FileName,
7171
crate attrs: Attributes,
7272
crate primitives: Vec<(DefId, PrimitiveType)>,

src/librustdoc/formats/cache.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
88
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
99
use rustc_middle::middle::privacy::AccessLevels;
1010
use rustc_span::source_map::FileName;
11+
use rustc_span::Symbol;
1112

1213
use crate::clean::{self, GetDefId};
1314
use crate::config::RenderInfo;
@@ -74,7 +75,7 @@ crate struct Cache {
7475
crate implementors: FxHashMap<DefId, Vec<Impl>>,
7576

7677
/// Cache of where external crate documentation can be found.
77-
crate extern_locations: FxHashMap<CrateNum, (String, PathBuf, ExternalLocation)>,
78+
crate extern_locations: FxHashMap<CrateNum, (Symbol, PathBuf, ExternalLocation)>,
7879

7980
/// Cache of where documentation for primitives can be found.
8081
crate primitive_locations: FxHashMap<clean::PrimitiveType, DefId>,
@@ -173,10 +174,10 @@ impl Cache {
173174
},
174175
_ => PathBuf::new(),
175176
};
176-
let extern_url = extern_html_root_urls.get(&e.name).map(|u| &**u);
177+
let extern_url = extern_html_root_urls.get(&*e.name.as_str()).map(|u| &**u);
177178
cache
178179
.extern_locations
179-
.insert(n, (e.name.clone(), src_root, extern_location(e, extern_url, &dst)));
180+
.insert(n, (e.name, src_root, extern_location(e, extern_url, &dst)));
180181

181182
let did = DefId { krate: n, index: CRATE_DEF_INDEX };
182183
cache.external_paths.insert(did, (vec![e.name.to_string()], ItemType::Module));
@@ -195,7 +196,7 @@ impl Cache {
195196
cache.primitive_locations.insert(prim, def_id);
196197
}
197198

198-
cache.stack.push(krate.name.clone());
199+
cache.stack.push(krate.name.to_string());
199200
krate = cache.fold_crate(krate);
200201

201202
for (trait_did, dids, impl_) in cache.orphan_trait_impls.drain(..) {
@@ -340,7 +341,7 @@ impl DocFolder for Cache {
340341

341342
// Keep track of the fully qualified path for this item.
342343
let pushed = match item.name {
343-
Some(ref n) if !n.is_empty() => {
344+
Some(n) if !n.is_empty() => {
344345
self.stack.push(n.to_string());
345346
true
346347
}

src/librustdoc/formats/renderer.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::sync::Arc;
33
use rustc_data_structures::sync::Lrc;
44
use rustc_session::Session;
55
use rustc_span::edition::Edition;
6-
use rustc_span::Symbol;
76

87
use crate::clean;
98
use crate::config::{RenderInfo, RenderOptions};
@@ -76,7 +75,7 @@ crate fn run_format<T: FormatRenderer>(
7675
None => return Ok(()),
7776
};
7877

79-
item.name = Some(Symbol::intern(&krate.name));
78+
item.name = Some(krate.name);
8079

8180
// Render the crate documentation
8281
let mut work = vec![(format_renderer.clone(), item)];

src/librustdoc/html/render/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ crate fn extern_location(
3131
) -> ExternalLocation {
3232
use ExternalLocation::*;
3333
// See if there's documentation generated into the local directory
34-
let local_location = dst.join(&e.name);
34+
let local_location = dst.join(&*e.name.as_str());
3535
if local_location.is_dir() {
3636
return Local;
3737
}

src/librustdoc/html/render/mod.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,15 @@ impl FormatRenderer for Context {
418418
// If user passed in `--playground-url` arg, we fill in crate name here
419419
let mut playground = None;
420420
if let Some(url) = playground_url {
421-
playground = Some(markdown::Playground { crate_name: Some(krate.name.clone()), url });
421+
playground =
422+
Some(markdown::Playground { crate_name: Some(krate.name.to_string()), url });
422423
}
423424
let mut layout = layout::Layout {
424425
logo: String::new(),
425426
favicon: String::new(),
426427
external_html,
427428
default_settings,
428-
krate: krate.name.clone(),
429+
krate: krate.name.to_string(),
429430
css_file_extension: extension_css,
430431
generate_search_filter,
431432
};
@@ -445,7 +446,7 @@ impl FormatRenderer for Context {
445446
}
446447
(sym::html_playground_url, Some(s)) => {
447448
playground = Some(markdown::Playground {
448-
crate_name: Some(krate.name.clone()),
449+
crate_name: Some(krate.name.to_string()),
449450
url: s.to_string(),
450451
});
451452
}
@@ -530,7 +531,7 @@ impl FormatRenderer for Context {
530531
}
531532

532533
fn after_krate(&mut self, krate: &clean::Crate, cache: &Cache) -> Result<(), Error> {
533-
let final_file = self.dst.join(&krate.name).join("all.html");
534+
let final_file = self.dst.join(&*krate.name.as_str()).join("all.html");
534535
let settings_file = self.dst.join("settings.html");
535536
let crate_name = krate.name.clone();
536537

@@ -1019,7 +1020,8 @@ themePicker.onblur = handleThemeButtonsBlur;
10191020
}
10201021

10211022
let dst = cx.dst.join(&format!("source-files{}.js", cx.shared.resource_suffix));
1022-
let (mut all_sources, _krates) = try_err!(collect(&dst, &krate.name, "sourcesIndex"), &dst);
1023+
let (mut all_sources, _krates) =
1024+
try_err!(collect(&dst, &krate.name.as_str(), "sourcesIndex"), &dst);
10231025
all_sources.push(format!(
10241026
"sourcesIndex[\"{}\"] = {};",
10251027
&krate.name,
@@ -1035,7 +1037,7 @@ themePicker.onblur = handleThemeButtonsBlur;
10351037

10361038
// Update the search index
10371039
let dst = cx.dst.join(&format!("search-index{}.js", cx.shared.resource_suffix));
1038-
let (mut all_indexes, mut krates) = try_err!(collect_json(&dst, &krate.name), &dst);
1040+
let (mut all_indexes, mut krates) = try_err!(collect_json(&dst, &krate.name.as_str()), &dst);
10391041
all_indexes.push(search_index);
10401042

10411043
// Sort the indexes by crate so the file will be generated identically even
@@ -1070,7 +1072,7 @@ themePicker.onblur = handleThemeButtonsBlur;
10701072
extra_scripts: &[],
10711073
static_extra_scripts: &[],
10721074
};
1073-
krates.push(krate.name.clone());
1075+
krates.push(krate.name.to_string());
10741076
krates.sort();
10751077
krates.dedup();
10761078

@@ -1162,7 +1164,7 @@ themePicker.onblur = handleThemeButtonsBlur;
11621164
mydst.push(&format!("{}.{}.js", remote_item_type, remote_path[remote_path.len() - 1]));
11631165

11641166
let (mut all_implementors, _) =
1165-
try_err!(collect(&mydst, &krate.name, "implementors"), &mydst);
1167+
try_err!(collect(&mydst, &krate.name.as_str(), "implementors"), &mydst);
11661168
all_implementors.push(implementors);
11671169
// Sort the implementors by crate so the file will be generated
11681170
// identically even with rustdoc running in parallel.
@@ -1648,16 +1650,17 @@ impl Context {
16481650
};
16491651
let file = &file;
16501652

1653+
let symbol;
16511654
let (krate, path) = if cnum == LOCAL_CRATE {
16521655
if let Some(path) = self.shared.local_sources.get(file) {
1653-
(&self.shared.layout.krate, path)
1656+
(self.shared.layout.krate.as_str(), path)
16541657
} else {
16551658
return None;
16561659
}
16571660
} else {
16581661
let (krate, src_root) = match *cache.extern_locations.get(&cnum)? {
1659-
(ref name, ref src, ExternalLocation::Local) => (name, src),
1660-
(ref name, ref src, ExternalLocation::Remote(ref s)) => {
1662+
(name, ref src, ExternalLocation::Local) => (name, src),
1663+
(name, ref src, ExternalLocation::Remote(ref s)) => {
16611664
root = s.to_string();
16621665
(name, src)
16631666
}
@@ -1671,7 +1674,8 @@ impl Context {
16711674
let mut fname = file.file_name().expect("source has no filename").to_os_string();
16721675
fname.push(".html");
16731676
path.push_str(&fname.to_string_lossy());
1674-
(krate, &path)
1677+
symbol = krate.as_str();
1678+
(&*symbol, &path)
16751679
};
16761680

16771681
let loline = item.source.lo(self.sess()).line;

src/librustdoc/html/sources.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ crate fn render(
1919
krate: clean::Crate,
2020
) -> Result<clean::Crate, Error> {
2121
info!("emitting source files");
22-
let dst = dst.join("src").join(&krate.name);
22+
let dst = dst.join("src").join(&*krate.name.as_str());
2323
scx.ensure_dir(&dst)?;
2424
let mut folder = SourceCollector { dst, scx };
2525
Ok(folder.fold_crate(krate))

src/librustdoc/json/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl FormatRenderer for JsonRenderer {
223223
(
224224
k.as_u32(),
225225
types::ExternalCrate {
226-
name: v.0.clone(),
226+
name: v.0.to_string(),
227227
html_root_url: match &v.2 {
228228
ExternalLocation::Remote(s) => Some(s.clone()),
229229
_ => None,

src/librustdoc/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,12 @@ fn main_options(options: config::Options) -> MainResult {
519519
// compiler all the way through the analysis passes. The rustdoc output is
520520
// then generated from the cleaned AST of the crate. This runs all the
521521
// plug/cleaning passes.
522-
let crate_name = options.crate_name.clone();
523522
let crate_version = options.crate_version.clone();
524523
let output_format = options.output_format;
525524
let (mut krate, renderinfo, renderopts, sess) = core::run_core(options);
526525

527526
info!("finished with rustc");
528527

529-
if let Some(name) = crate_name {
530-
krate.name = name
531-
}
532-
533528
krate.version = crate_version;
534529

535530
if show_coverage {

0 commit comments

Comments
 (0)