diff options
| author | Tyson Nottingham <tgnottingham@gmail.com> | 2020-09-20 17:40:51 -0700 |
|---|---|---|
| committer | Tyson Nottingham <tgnottingham@gmail.com> | 2020-12-03 18:36:34 -0800 |
| commit | 75de8286c04af256762804ee96b08a68d2aba279 (patch) | |
| tree | 8f97b1971b229b38eddd739c3ca618b63eb661cd /compiler/rustc_span/src/lib.rs | |
| parent | 0987b841987fb7ffc09848c185d671ff3bea7d35 (diff) | |
| download | rust-75de8286c04af256762804ee96b08a68d2aba279.tar.gz rust-75de8286c04af256762804ee96b08a68d2aba279.zip | |
rustc_span: add span_data_to_lines_and_cols to caching source map view
Gives a performance increase over calling byte_pos_to_line_and_col twice, partially because it decreases the function calling overhead, potentially because it doesn't populate the line cache with lines that turn out to belong to invalid spans, and likely because of some other incidental improvements made possible by having more context available.
Diffstat (limited to 'compiler/rustc_span/src/lib.rs')
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 11a49d1ab88..24b06f27afd 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -1848,6 +1848,10 @@ pub trait HashStableContext { &mut self, byte: BytePos, ) -> Option<(Lrc<SourceFile>, usize, BytePos)>; + fn span_data_to_lines_and_cols( + &mut self, + span: &SpanData, + ) -> Option<(Lrc<SourceFile>, usize, BytePos, usize, BytePos)>; } impl<CTX> HashStable<CTX> for Span @@ -1880,22 +1884,8 @@ where // position that belongs to it, as opposed to hashing the first // position past it. let span = self.data(); - let (file_lo, line_lo, col_lo) = match ctx.byte_pos_to_line_and_col(span.lo) { - Some(pos) => pos, - None => { - Hash::hash(&TAG_INVALID_SPAN, hasher); - span.ctxt.hash_stable(ctx, hasher); - return; - } - }; - - if !file_lo.contains(span.hi) { - Hash::hash(&TAG_INVALID_SPAN, hasher); - span.ctxt.hash_stable(ctx, hasher); - return; - } - - let (_, line_hi, col_hi) = match ctx.byte_pos_to_line_and_col(span.hi) { + let (file, line_lo, col_lo, line_hi, col_hi) = match ctx.span_data_to_lines_and_cols(&span) + { Some(pos) => pos, None => { Hash::hash(&TAG_INVALID_SPAN, hasher); @@ -1907,7 +1897,7 @@ where Hash::hash(&TAG_VALID_SPAN, hasher); // We truncate the stable ID hash and line and column numbers. The chances // of causing a collision this way should be minimal. - Hash::hash(&(file_lo.name_hash as u64), hasher); + Hash::hash(&(file.name_hash as u64), hasher); // Hash both the length and the end location (line/column) of a span. If we // hash only the length, for example, then two otherwise equal spans with |
