Skip to content

Commit 1460cfe

Browse files
committed
Only unpack span data once.
1 parent 6dcc861 commit 1460cfe

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

compiler/rustc_span/src/source_map.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -911,12 +911,13 @@ impl SourceMap {
911911

912912
/// Returns a new span representing just the last character of this span.
913913
pub fn end_point(&self, sp: Span) -> Span {
914-
let pos = sp.hi().0;
914+
let sp = sp.data();
915+
let pos = sp.hi.0;
915916

916917
let width = self.find_width_of_character_at_span(sp, false);
917918
let corrected_end_position = pos.checked_sub(width).unwrap_or(pos);
918919

919-
let end_point = BytePos(cmp::max(corrected_end_position, sp.lo().0));
920+
let end_point = BytePos(cmp::max(corrected_end_position, sp.lo.0));
920921
sp.with_lo(end_point)
921922
}
922923

@@ -930,8 +931,9 @@ impl SourceMap {
930931
if sp.is_dummy() {
931932
return sp;
932933
}
933-
let start_of_next_point = sp.hi().0;
934934

935+
let sp = sp.data();
936+
let start_of_next_point = sp.hi.0;
935937
let width = self.find_width_of_character_at_span(sp, true);
936938
// If the width is 1, then the next span should only contain the next char besides current ending.
937939
// However, in the case of a multibyte character, where the width != 1, the next span should
@@ -940,7 +942,7 @@ impl SourceMap {
940942
start_of_next_point.checked_add(width).unwrap_or(start_of_next_point);
941943

942944
let end_of_next_point = BytePos(cmp::max(start_of_next_point + 1, end_of_next_point));
943-
Span::new(BytePos(start_of_next_point), end_of_next_point, sp.ctxt(), None)
945+
Span::new(BytePos(start_of_next_point), end_of_next_point, sp.ctxt, None)
944946
}
945947

946948
/// Check whether span is followed by some specified expected string in limit scope
@@ -963,9 +965,7 @@ impl SourceMap {
963965
/// Finds the width of the character, either before or after the end of provided span,
964966
/// depending on the `forwards` parameter.
965967
#[instrument(skip(self, sp))]
966-
fn find_width_of_character_at_span(&self, sp: Span, forwards: bool) -> u32 {
967-
let sp = sp.data();
968-
968+
fn find_width_of_character_at_span(&self, sp: SpanData, forwards: bool) -> u32 {
969969
if sp.lo == sp.hi && !forwards {
970970
debug!("early return empty span");
971971
return 1;

0 commit comments

Comments
 (0)