@@ -42,6 +42,7 @@ const TAG_EXPN_DATA: u8 = 1;
4242// Tags for encoding Symbol's
4343const SYMBOL_STR : u8 = 0 ;
4444const SYMBOL_OFFSET : u8 = 1 ;
45+ const SYMBOL_PREINTERNED : u8 = 2 ;
4546
4647/// Provides an interface to incremental compilation data cached from the
4748/// previous compilation session. This data will eventually include the results
@@ -745,6 +746,10 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for Symbol {
745746
746747 sym
747748 }
749+ SYMBOL_PREINTERNED => {
750+ let symbol_index = d. read_u32 ( ) ;
751+ Symbol :: new_from_decoded ( symbol_index)
752+ }
748753 _ => unreachable ! ( ) ,
749754 }
750755 }
@@ -939,17 +944,24 @@ impl<'a, 'tcx> Encodable<CacheEncoder<'a, 'tcx>> for Span {
939944// copy&paste impl from rustc_metadata
940945impl < ' a , ' tcx > Encodable < CacheEncoder < ' a , ' tcx > > for Symbol {
941946 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+ }
953965 }
954966 }
955967 }
0 commit comments