Skip to content

Commit f7eabf5

Browse files
committed
Revert "Slow down Symbol::as_str"
This reverts commit ae3ea6f3db2699f1943637198d459435ebf78e76.
1 parent 5d192a4 commit f7eabf5

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

compiler/rustc_macros/src/symbols.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,6 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec<syn::Error>) {
201201
}
202202
let _ = counter; // for future use
203203

204-
// We have finished collecting symbol strings.
205-
let static_symbols_len = symbol_strings.len();
206-
207-
// Build the body of STATIC_SYMBOLS.
208-
let symbol_strings_tokens: TokenStream = symbol_strings.iter().map(|s| quote!(#s,)).collect();
209-
210204
// Build the PHF map. This translates from strings to Symbol values.
211205
let mut phf_map = phf_codegen::Map::<&str>::new();
212206
for (symbol_index, symbol) in symbol_strings.iter().enumerate() {
@@ -242,10 +236,6 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec<syn::Error>) {
242236
}
243237
}
244238

245-
static STATIC_SYMBOLS: [&str; #static_symbols_len as usize] = [
246-
#symbol_strings_tokens
247-
];
248-
249239
static STATIC_SYMBOLS_PHF: ::phf::Map<&'static str, Symbol> = #phf_map_expr;
250240
};
251241

compiler/rustc_span/src/symbol.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,24 +1453,19 @@ impl Symbol {
14531453

14541454
/// Maps a string to its interned representation.
14551455
pub fn intern(string: &str) -> Self {
1456-
// if let Some(symbol) = STATIC_SYMBOLS_PHF.get(string) {
1457-
// *symbol
1458-
// } else {
1459-
// with_interner(|interner| interner.intern(string))
1460-
// }
1461-
with_interner(|interner| interner.intern(string))
1456+
if let Some(symbol) = STATIC_SYMBOLS_PHF.get(string) {
1457+
*symbol
1458+
} else {
1459+
with_interner(|interner| interner.intern(string))
1460+
}
14621461
}
14631462

14641463
/// Convert to a `SymbolStr`. This is a slowish operation because it
14651464
/// requires locking the symbol interner.
14661465
pub fn as_str(self) -> SymbolStr {
1467-
if let Some(string) = STATIC_SYMBOLS.get(self.0.as_usize()) {
1468-
SymbolStr { string }
1469-
} else {
1470-
with_interner(|interner| unsafe {
1471-
SymbolStr { string: std::mem::transmute::<&str, &str>(interner.get(self)) }
1472-
})
1473-
}
1466+
with_interner(|interner| unsafe {
1467+
SymbolStr { string: std::mem::transmute::<&str, &str>(interner.get(self)) }
1468+
})
14741469
}
14751470

14761471
pub fn as_u32(self) -> u32 {

0 commit comments

Comments
 (0)