1
Fork 0

rmeta/query cache: don't write string values of preinterned symbols

This commit is contained in:
klensy 2022-08-20 15:39:21 +03:00
parent 0016356f2b
commit f6329485a8
5 changed files with 51 additions and 22 deletions

View file

@ -631,6 +631,10 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for Symbol {
sym
}
SYMBOL_PREINTERNED => {
let symbol_index = d.read_u32();
Symbol::new_from_decoded(symbol_index)
}
_ => unreachable!(),
}
}

View file

@ -317,17 +317,24 @@ impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for Span {
impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for Symbol {
fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) {
match s.symbol_table.entry(*self) {
Entry::Vacant(o) => {
s.opaque.emit_u8(SYMBOL_STR);
let pos = s.opaque.position();
o.insert(pos);
s.emit_str(self.as_str());
}
Entry::Occupied(o) => {
let x = o.get().clone();
s.emit_u8(SYMBOL_OFFSET);
s.emit_usize(x);
// if symbol preinterned, emit tag and symbol index
if self.is_preinterned() {
s.opaque.emit_u8(SYMBOL_PREINTERNED);
s.opaque.emit_u32(self.as_u32());
} else {
// otherwise write it as string or as offset to it
match s.symbol_table.entry(*self) {
Entry::Vacant(o) => {
s.opaque.emit_u8(SYMBOL_STR);
let pos = s.opaque.position();
o.insert(pos);
s.emit_str(self.as_str());
}
Entry::Occupied(o) => {
let x = o.get().clone();
s.emit_u8(SYMBOL_OFFSET);
s.emit_usize(x);
}
}
}
}

View file

@ -448,6 +448,7 @@ const TAG_PARTIAL_SPAN: u8 = 2;
// Tags for encoding Symbol's
const SYMBOL_STR: u8 = 0;
const SYMBOL_OFFSET: u8 = 1;
const SYMBOL_PREINTERNED: u8 = 2;
pub fn provide(providers: &mut Providers) {
encoder::provide(providers);