@@ -82,6 +82,8 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
82
82
// within the CodeMap.
83
83
// Also note that we are hashing byte offsets for the column, not unicode
84
84
// 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.
85
87
fn hash_span ( & mut self , span : Span ) {
86
88
debug_assert ! ( self . hash_spans) ;
87
89
debug ! ( "hash_span: st={:?}" , self . st) ;
@@ -98,21 +100,35 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
98
100
span. hi
99
101
} ;
100
102
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 {
105
104
NO_EXPANSION => SawSpanExpnKind :: NoExpansion ,
106
105
COMMAND_LINE_EXPN => SawSpanExpnKind :: CommandLine ,
107
106
_ => SawSpanExpnKind :: SomeExpansion ,
108
107
} ;
109
108
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 ) ;
114
130
115
- if expansion_kind == SawSpanExpnKind :: SomeExpansion {
131
+ if expn_kind == SawSpanExpnKind :: SomeExpansion {
116
132
let call_site = self . codemap . codemap ( ) . source_callsite ( span) ;
117
133
self . hash_span ( call_site) ;
118
134
}
@@ -184,9 +200,13 @@ enum SawAbiComponent<'a> {
184
200
SawAssocTypeBinding ,
185
201
SawAttribute ( ast:: AttrStyle ) ,
186
202
SawMacroDef ,
187
- SawSpan ( Option < ( & ' a str , usize , BytePos ) > ,
188
- Option < ( & ' a str , usize , BytePos ) > ,
203
+ SawSpan ( & ' a str ,
204
+ usize , BytePos ,
205
+ usize , BytePos ,
189
206
SawSpanExpnKind ) ,
207
+ SawSpanTwoFiles ( & ' a str , usize , BytePos ,
208
+ & ' a str , usize , BytePos ,
209
+ SawSpanExpnKind ) ,
190
210
}
191
211
192
212
/// SawExprComponent carries all of the information that we want
0 commit comments