@@ -30,7 +30,7 @@ use std::borrow::Cow;
3030use std:: cell:: { Cell , RefCell } ;
3131use std:: cmp:: { self , Ordering } ;
3232use std:: fmt;
33- use std:: hash:: Hasher ;
33+ use std:: hash:: { Hasher , Hash } ;
3434use std:: ops:: { Add , Sub } ;
3535use std:: path:: PathBuf ;
3636use std:: rc:: Rc ;
@@ -691,6 +691,8 @@ pub struct FileMap {
691691 pub multibyte_chars : RefCell < Vec < MultiByteChar > > ,
692692 /// Width of characters that are not narrow in the source code
693693 pub non_narrow_chars : RefCell < Vec < NonNarrowChar > > ,
694+ /// A hash of the filename, used for speeding up the incr. comp. hashing.
695+ pub name_hash : u128 ,
694696}
695697
696698impl Encodable for FileMap {
@@ -752,6 +754,9 @@ impl Encodable for FileMap {
752754 } ) ?;
753755 s. emit_struct_field ( "non_narrow_chars" , 8 , |s| {
754756 ( * self . non_narrow_chars . borrow ( ) ) . encode ( s)
757+ } ) ?;
758+ s. emit_struct_field ( "name_hash" , 9 , |s| {
759+ self . name_hash . encode ( s)
755760 } )
756761 } )
757762 }
@@ -801,6 +806,8 @@ impl Decodable for FileMap {
801806 d. read_struct_field ( "multibyte_chars" , 7 , |d| Decodable :: decode ( d) ) ?;
802807 let non_narrow_chars: Vec < NonNarrowChar > =
803808 d. read_struct_field ( "non_narrow_chars" , 8 , |d| Decodable :: decode ( d) ) ?;
809+ let name_hash: u128 =
810+ d. read_struct_field ( "name_hash" , 9 , |d| Decodable :: decode ( d) ) ?;
804811 Ok ( FileMap {
805812 name,
806813 name_was_remapped,
@@ -816,7 +823,8 @@ impl Decodable for FileMap {
816823 external_src : RefCell :: new ( ExternalSource :: AbsentOk ) ,
817824 lines : RefCell :: new ( lines) ,
818825 multibyte_chars : RefCell :: new ( multibyte_chars) ,
819- non_narrow_chars : RefCell :: new ( non_narrow_chars)
826+ non_narrow_chars : RefCell :: new ( non_narrow_chars) ,
827+ name_hash,
820828 } )
821829 } )
822830 }
@@ -836,9 +844,16 @@ impl FileMap {
836844 start_pos : BytePos ) -> FileMap {
837845 remove_bom ( & mut src) ;
838846
839- let mut hasher: StableHasher < u128 > = StableHasher :: new ( ) ;
840- hasher. write ( src. as_bytes ( ) ) ;
841- let src_hash = hasher. finish ( ) ;
847+ let src_hash = {
848+ let mut hasher: StableHasher < u128 > = StableHasher :: new ( ) ;
849+ hasher. write ( src. as_bytes ( ) ) ;
850+ hasher. finish ( )
851+ } ;
852+ let name_hash = {
853+ let mut hasher: StableHasher < u128 > = StableHasher :: new ( ) ;
854+ name. hash ( & mut hasher) ;
855+ hasher. finish ( )
856+ } ;
842857 let end_pos = start_pos. to_usize ( ) + src. len ( ) ;
843858
844859 FileMap {
@@ -854,6 +869,7 @@ impl FileMap {
854869 lines : RefCell :: new ( Vec :: new ( ) ) ,
855870 multibyte_chars : RefCell :: new ( Vec :: new ( ) ) ,
856871 non_narrow_chars : RefCell :: new ( Vec :: new ( ) ) ,
872+ name_hash,
857873 }
858874 }
859875
0 commit comments