Skip to content

Commit d0cc986

Browse files
committed
check_doc_keyword: don't alloc string for emptiness check
check_doc_alias_value: get argument as Symbol to prevent needless string convertions check_doc_attrs: don't alloc vec, iterate over slice. Vec introduced in rust-lang#83149, but no perf run posted on merge replace as_str() check with symbol check get_single_str_from_tts: don't prealloc string trivial string to str replace LifetimeScopeForPath::NonElided use Vec<Symbol> instead of Vec<String> AssertModuleSource use BTreeSet<Symbol> instead of BTreeSet<String> CrateInfo.crate_name replace FxHashMap<CrateNum, String> with FxHashMap<CrateNum, Symbol>
1 parent f262ca1 commit d0cc986

File tree

15 files changed

+56
-65
lines changed

15 files changed

+56
-65
lines changed

compiler/rustc_builtin_macros/src/compile_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn expand_compile_error<'cx>(
1313
return DummyResult::any(sp);
1414
};
1515

16-
cx.span_err(sp, &var);
16+
cx.span_err(sp, var.as_str());
1717

1818
DummyResult::any(sp)
1919
}

compiler/rustc_builtin_macros/src/env.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ pub fn expand_option_env<'cx>(
2121
};
2222

2323
let sp = cx.with_def_site_ctxt(sp);
24-
let value = env::var(&var.as_str()).ok().as_deref().map(Symbol::intern);
25-
cx.sess.parse_sess.env_depinfo.borrow_mut().insert((Symbol::intern(&var), value));
24+
let value = env::var(var.as_str()).ok().as_deref().map(Symbol::intern);
25+
cx.sess.parse_sess.env_depinfo.borrow_mut().insert((var, value));
2626
let e = match value {
2727
None => {
2828
let lt = cx.lifetime(sp, Ident::new(kw::StaticLifetime, sp));

compiler/rustc_builtin_macros/src/source_util.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn expand_include<'cx>(
104104
return DummyResult::any(sp);
105105
};
106106
// The file will be added to the code map by the parser
107-
let file = match resolve_path(cx, file, sp) {
107+
let file = match resolve_path(cx, file.as_str(), sp) {
108108
Ok(f) => f,
109109
Err(mut err) => {
110110
err.emit();
@@ -173,7 +173,7 @@ pub fn expand_include_str(
173173
let Some(file) = get_single_str_from_tts(cx, sp, tts, "include_str!") else {
174174
return DummyResult::any(sp);
175175
};
176-
let file = match resolve_path(cx, file, sp) {
176+
let file = match resolve_path(cx, file.as_str(), sp) {
177177
Ok(f) => f,
178178
Err(mut err) => {
179179
err.emit();
@@ -207,7 +207,7 @@ pub fn expand_include_bytes(
207207
let Some(file) = get_single_str_from_tts(cx, sp, tts, "include_bytes!") else {
208208
return DummyResult::any(sp);
209209
};
210-
let file = match resolve_path(cx, file, sp) {
210+
let file = match resolve_path(cx, file.as_str(), sp) {
211211
Ok(f) => f,
212212
Err(mut err) => {
213213
err.emit();

compiler/rustc_codegen_cranelift/src/driver/jit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ fn load_imported_symbols_for_jit(
288288
match data[cnum.as_usize() - 1] {
289289
Linkage::NotLinked | Linkage::IncludedFromDylib => {}
290290
Linkage::Static => {
291-
let name = &crate_info.crate_name[&cnum];
292-
let mut err = sess.struct_err(&format!("Can't load static lib {}", name.as_str()));
291+
let name = crate_info.crate_name[&cnum];
292+
let mut err = sess.struct_err(&format!("Can't load static lib {}", name));
293293
err.note("rustc_codegen_cranelift can only load dylibs in JIT mode.");
294294
err.emit();
295295
}

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub fn each_linked_rlib(
216216
Some(_) => {}
217217
None => return Err("could not find formats for rlibs".to_string()),
218218
}
219-
let name = &info.crate_name[&cnum];
219+
let name = info.crate_name[&cnum];
220220
let used_crate_source = &info.used_crate_source[&cnum];
221221
if let Some((path, _)) = &used_crate_source.rlib {
222222
f(cnum, &path);
@@ -467,7 +467,7 @@ fn link_staticlib<'a, B: ArchiveBuilder<'a>>(
467467
let mut all_native_libs = vec![];
468468

469469
let res = each_linked_rlib(&codegen_results.crate_info, &mut |cnum, path| {
470-
let name = &codegen_results.crate_info.crate_name[&cnum];
470+
let name = codegen_results.crate_info.crate_name[&cnum];
471471
let native_libs = &codegen_results.crate_info.native_libraries[&cnum];
472472

473473
// Here when we include the rlib into our staticlib we need to make a

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ impl CrateInfo {
861861
for &cnum in crates.iter() {
862862
info.native_libraries
863863
.insert(cnum, tcx.native_libraries(cnum).iter().map(Into::into).collect());
864-
info.crate_name.insert(cnum, tcx.crate_name(cnum).to_string());
864+
info.crate_name.insert(cnum, tcx.crate_name(cnum));
865865
info.used_crate_source.insert(cnum, tcx.used_crate_source(cnum).clone());
866866
if tcx.is_compiler_builtins(cnum) {
867867
info.compiler_builtins = Some(cnum);

compiler/rustc_codegen_ssa/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub struct CrateInfo {
146146
pub profiler_runtime: Option<CrateNum>,
147147
pub is_no_builtins: FxHashSet<CrateNum>,
148148
pub native_libraries: FxHashMap<CrateNum, Vec<NativeLib>>,
149-
pub crate_name: FxHashMap<CrateNum, String>,
149+
pub crate_name: FxHashMap<CrateNum, Symbol>,
150150
pub used_libraries: Vec<NativeLib>,
151151
pub used_crate_source: FxHashMap<CrateNum, Lrc<CrateSource>>,
152152
pub used_crates: Vec<CrateNum>,

compiler/rustc_expand/src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ pub fn get_single_str_from_tts(
12151215
sp: Span,
12161216
tts: TokenStream,
12171217
name: &str,
1218-
) -> Option<String> {
1218+
) -> Option<Symbol> {
12191219
let mut p = cx.new_parser_from_tts(tts);
12201220
if p.token == token::Eof {
12211221
cx.span_err(sp, &format!("{} takes 1 argument", name));
@@ -1227,7 +1227,7 @@ pub fn get_single_str_from_tts(
12271227
if p.token != token::Eof {
12281228
cx.span_err(sp, &format!("{} takes 1 argument", name));
12291229
}
1230-
expr_to_string(cx, ret, "argument must be a string literal").map(|(s, _)| s.to_string())
1230+
expr_to_string(cx, ret, "argument must be a string literal").map(|(s, _)| s)
12311231
}
12321232

12331233
/// Extracts comma-separated expressions from `tts`.

compiler/rustc_incremental/src/assert_module_sources.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
//! was re-used.
2323
2424
use rustc_ast as ast;
25+
use rustc_data_structures::stable_set::FxHashSet;
2526
use rustc_hir::def_id::LOCAL_CRATE;
2627
use rustc_middle::mir::mono::CodegenUnitNameBuilder;
2728
use rustc_middle::ty::TyCtxt;
2829
use rustc_session::cgu_reuse_tracker::*;
2930
use rustc_span::symbol::{sym, Symbol};
30-
use std::collections::BTreeSet;
3131

3232
#[allow(missing_docs)]
3333
pub fn assert_module_sources(tcx: TyCtxt<'_>) {
@@ -36,12 +36,8 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) {
3636
return;
3737
}
3838

39-
let available_cgus = tcx
40-
.collect_and_partition_mono_items(())
41-
.1
42-
.iter()
43-
.map(|cgu| cgu.name().to_string())
44-
.collect::<BTreeSet<String>>();
39+
let available_cgus =
40+
tcx.collect_and_partition_mono_items(()).1.iter().map(|cgu| cgu.name()).collect();
4541

4642
let ams = AssertModuleSource { tcx, available_cgus };
4743

@@ -53,7 +49,7 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) {
5349

5450
struct AssertModuleSource<'tcx> {
5551
tcx: TyCtxt<'tcx>,
56-
available_cgus: BTreeSet<String>,
52+
available_cgus: FxHashSet<Symbol>,
5753
}
5854

5955
impl<'tcx> AssertModuleSource<'tcx> {
@@ -124,18 +120,17 @@ impl<'tcx> AssertModuleSource<'tcx> {
124120

125121
debug!("mapping '{}' to cgu name '{}'", self.field(attr, sym::module), cgu_name);
126122

127-
if !self.available_cgus.contains(cgu_name.as_str()) {
123+
if !self.available_cgus.contains(&cgu_name) {
124+
let mut cgu_names: Vec<&str> =
125+
self.available_cgus.iter().map(|cgu| cgu.as_str()).collect();
126+
cgu_names.sort();
128127
self.tcx.sess.span_err(
129128
attr.span,
130129
&format!(
131130
"no module named `{}` (mangled: {}). Available modules: {}",
132131
user_path,
133132
cgu_name,
134-
self.available_cgus
135-
.iter()
136-
.map(|cgu| cgu.to_string())
137-
.collect::<Vec<_>>()
138-
.join(", ")
133+
cgu_names.join(", ")
139134
),
140135
);
141136
}

compiler/rustc_middle/src/middle/resolve_lifetime.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
66
use rustc_hir::def_id::{DefId, LocalDefId};
77
use rustc_hir::ItemLocalId;
88
use rustc_macros::HashStable;
9+
use rustc_span::symbol::Symbol;
910

1011
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)]
1112
pub enum Region {
@@ -23,7 +24,7 @@ pub enum Region {
2324
pub enum LifetimeScopeForPath {
2425
// Contains all lifetime names that are in scope and could possibly be used in generics
2526
// arguments of path.
26-
NonElided(Vec<String>),
27+
NonElided(Vec<Symbol>),
2728

2829
// Information that allows us to suggest args of the form `<'_>` in case
2930
// no generic arguments were provided for a path.

0 commit comments

Comments
 (0)