Skip to content

Commit

Permalink
Avoid unnecessary line lookup.
Browse files Browse the repository at this point in the history
`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.)
  • Loading branch information
nnethercote committed Jun 29, 2023
1 parent 7ba31b9 commit 9db001d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/debuginfo/line_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl DebugContext {

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

(
file,
Expand Down

0 comments on commit 9db001d

Please sign in to comment.