Skip to content

Commit a13be65

Browse files
committed
Avoid unnecessary line lookup.
`lookup_debug_loc` calls `SourceMap::lookup_line`, which does a binary search over the files, and then a binary search over the lines within the found file. It then calls `SourceFile::line_begin_pos`, which redoes the binary search over the lines within the found file. This commit removes the second binary search over the lines, instead getting the line starting pos directly using the result of the first binary search over the lines. (And likewise for `get_span_loc`, in the cranelift backend.)
1 parent 8084f39 commit a13be65

File tree

2 files changed

+2
-2
lines changed
  • compiler

2 files changed

+2
-2
lines changed

compiler/rustc_codegen_cranelift/src/debuginfo/line_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl DebugContext {
8181

8282
match tcx.sess.source_map().lookup_line(span.lo()) {
8383
Ok(SourceFileAndLine { sf: file, line }) => {
84-
let line_pos = file.line_begin_pos(span.lo());
84+
let line_pos = file.lines(|lines| lines[line]);
8585

8686
(
8787
file,

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl CodegenCx<'_, '_> {
262262
pub fn lookup_debug_loc(&self, pos: BytePos) -> DebugLoc {
263263
let (file, line, col) = match self.sess().source_map().lookup_line(pos) {
264264
Ok(SourceFileAndLine { sf: file, line }) => {
265-
let line_pos = file.line_begin_pos(pos);
265+
let line_pos = file.lines(|lines| lines[line]);
266266

267267
// Use 1-based indexing.
268268
let line = (line + 1) as u32;

0 commit comments

Comments
 (0)