@@ -82,6 +82,8 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
8282 // within the CodeMap.
8383 // Also note that we are hashing byte offsets for the column, not unicode
8484 // codepoint offsets. For the purpose of the hash that's sufficient.
85+ // Also, hashing filenames is expensive so we avoid doing it twice when the
86+ // span starts and ends in the same file, which is almost always the case.
8587 fn hash_span ( & mut self , span : Span ) {
8688 debug_assert ! ( self . hash_spans) ;
8789 debug ! ( "hash_span: st={:?}" , self . st) ;
@@ -98,21 +100,35 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
98100 span. hi
99101 } ;
100102
101- let loc1 = self . codemap . byte_pos_to_line_and_col ( span. lo ) ;
102- let loc2 = self . codemap . byte_pos_to_line_and_col ( span_hi) ;
103-
104- let expansion_kind = match span. expn_id {
103+ let expn_kind = match span. expn_id {
105104 NO_EXPANSION => SawSpanExpnKind :: NoExpansion ,
106105 COMMAND_LINE_EXPN => SawSpanExpnKind :: CommandLine ,
107106 _ => SawSpanExpnKind :: SomeExpansion ,
108107 } ;
109108
110- SawSpan ( loc1. as_ref ( ) . map ( |& ( ref fm, line, col) | ( & fm. name [ ..] , line, col) ) ,
111- loc2. as_ref ( ) . map ( |& ( ref fm, line, col) | ( & fm. name [ ..] , line, col) ) ,
112- expansion_kind)
113- . hash ( self . st ) ;
109+ let loc1 = self . codemap . byte_pos_to_line_and_col ( span. lo ) ;
110+ let loc1 = loc1. as_ref ( )
111+ . map ( |& ( ref fm, line, col) | ( & fm. name [ ..] , line, col) )
112+ . unwrap_or ( ( "???" , 0 , BytePos ( 0 ) ) ) ;
113+
114+ let loc2 = self . codemap . byte_pos_to_line_and_col ( span_hi) ;
115+ let loc2 = loc2. as_ref ( )
116+ . map ( |& ( ref fm, line, col) | ( & fm. name [ ..] , line, col) )
117+ . unwrap_or ( ( "???" , 0 , BytePos ( 0 ) ) ) ;
118+
119+ let saw = if loc1. 0 == loc2. 0 {
120+ SawSpan ( loc1. 0 ,
121+ loc1. 1 , loc1. 2 ,
122+ loc2. 1 , loc2. 2 ,
123+ expn_kind)
124+ } else {
125+ SawSpanTwoFiles ( loc1. 0 , loc1. 1 , loc1. 2 ,
126+ loc2. 0 , loc2. 1 , loc2. 2 ,
127+ expn_kind)
128+ } ;
129+ saw. hash ( self . st ) ;
114130
115- if expansion_kind == SawSpanExpnKind :: SomeExpansion {
131+ if expn_kind == SawSpanExpnKind :: SomeExpansion {
116132 let call_site = self . codemap . codemap ( ) . source_callsite ( span) ;
117133 self . hash_span ( call_site) ;
118134 }
@@ -184,9 +200,13 @@ enum SawAbiComponent<'a> {
184200 SawAssocTypeBinding ,
185201 SawAttribute ( ast:: AttrStyle ) ,
186202 SawMacroDef ,
187- SawSpan ( Option < ( & ' a str , usize , BytePos ) > ,
188- Option < ( & ' a str , usize , BytePos ) > ,
203+ SawSpan ( & ' a str ,
204+ usize , BytePos ,
205+ usize , BytePos ,
189206 SawSpanExpnKind ) ,
207+ SawSpanTwoFiles ( & ' a str , usize , BytePos ,
208+ & ' a str , usize , BytePos ,
209+ SawSpanExpnKind ) ,
190210}
191211
192212/// SawExprComponent carries all of the information that we want
0 commit comments