@@ -42,6 +42,7 @@ const TAG_EXPN_DATA: u8 = 1;
42
42
// Tags for encoding Symbol's
43
43
const SYMBOL_STR : u8 = 0 ;
44
44
const SYMBOL_OFFSET : u8 = 1 ;
45
+ const SYMBOL_PREINTERNED : u8 = 2 ;
45
46
46
47
/// Provides an interface to incremental compilation data cached from the
47
48
/// previous compilation session. This data will eventually include the results
@@ -745,6 +746,10 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for Symbol {
745
746
746
747
sym
747
748
}
749
+ SYMBOL_PREINTERNED => {
750
+ let symbol_index = d. read_u32 ( ) ;
751
+ Symbol :: new_from_decoded ( symbol_index)
752
+ }
748
753
_ => unreachable ! ( ) ,
749
754
}
750
755
}
@@ -939,17 +944,24 @@ impl<'a, 'tcx> Encodable<CacheEncoder<'a, 'tcx>> for Span {
939
944
// copy&paste impl from rustc_metadata
940
945
impl < ' a , ' tcx > Encodable < CacheEncoder < ' a , ' tcx > > for Symbol {
941
946
fn encode ( & self , s : & mut CacheEncoder < ' a , ' tcx > ) {
942
- match s. symbol_table . entry ( * self ) {
943
- Entry :: Vacant ( o) => {
944
- s. encoder . emit_u8 ( SYMBOL_STR ) ;
945
- let pos = s. encoder . position ( ) ;
946
- o. insert ( pos) ;
947
- s. emit_str ( self . as_str ( ) ) ;
948
- }
949
- Entry :: Occupied ( o) => {
950
- let x = o. get ( ) . clone ( ) ;
951
- s. emit_u8 ( SYMBOL_OFFSET ) ;
952
- s. emit_usize ( x) ;
947
+ // if symbol preinterned, emit tag and symbol index
948
+ if self . is_preinterned ( ) {
949
+ s. encoder . emit_u8 ( SYMBOL_PREINTERNED ) ;
950
+ s. encoder . emit_u32 ( self . as_u32 ( ) ) ;
951
+ } else {
952
+ // otherwise write it as string or as offset to it
953
+ match s. symbol_table . entry ( * self ) {
954
+ Entry :: Vacant ( o) => {
955
+ s. encoder . emit_u8 ( SYMBOL_STR ) ;
956
+ let pos = s. encoder . position ( ) ;
957
+ o. insert ( pos) ;
958
+ s. emit_str ( self . as_str ( ) ) ;
959
+ }
960
+ Entry :: Occupied ( o) => {
961
+ let x = o. get ( ) . clone ( ) ;
962
+ s. emit_u8 ( SYMBOL_OFFSET ) ;
963
+ s. emit_usize ( x) ;
964
+ }
953
965
}
954
966
}
955
967
}
0 commit comments