mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Thread global symbol interner through as if it was a local
This commit is contained in:
parent
c4582f6d18
commit
0522503f14
3 changed files with 39 additions and 26 deletions
|
@ -1,28 +1,30 @@
|
|||
//! Symbol interner for proc-macro-srv
|
||||
|
||||
use std::{cell::RefCell, collections::HashMap};
|
||||
use std::{cell::RefCell, collections::HashMap, thread::LocalKey};
|
||||
use tt::SmolStr;
|
||||
|
||||
thread_local! {
|
||||
static SYMBOL_INTERNER: RefCell<SymbolInterner> = Default::default();
|
||||
pub(crate) static SYMBOL_INTERNER: RefCell<SymbolInterner> = Default::default();
|
||||
}
|
||||
|
||||
// ID for an interned symbol.
|
||||
#[derive(Hash, Eq, PartialEq, Copy, Clone)]
|
||||
pub struct Symbol(u32);
|
||||
|
||||
pub(crate) type SymbolInternerRef = &'static LocalKey<RefCell<SymbolInterner>>;
|
||||
|
||||
impl Symbol {
|
||||
pub(super) fn intern(data: &str) -> Symbol {
|
||||
SYMBOL_INTERNER.with(|i| i.borrow_mut().intern(data))
|
||||
pub(super) fn intern(interner: SymbolInternerRef, data: &str) -> Symbol {
|
||||
interner.with(|i| i.borrow_mut().intern(data))
|
||||
}
|
||||
|
||||
pub(super) fn text(&self) -> SmolStr {
|
||||
SYMBOL_INTERNER.with(|i| i.borrow().get(self).clone())
|
||||
pub(super) fn text(&self, interner: SymbolInternerRef) -> SmolStr {
|
||||
interner.with(|i| i.borrow().get(self).clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct SymbolInterner {
|
||||
pub(crate) struct SymbolInterner {
|
||||
idents: HashMap<SmolStr, u32>,
|
||||
ident_data: Vec<SmolStr>,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue