diff options
| author | bors <bors@rust-lang.org> | 2022-06-02 18:45:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-02 18:45:29 +0000 |
| commit | 2a18d124aaea78d2fad8be0135fa8182d40e32fb (patch) | |
| tree | e4c387004ae1ffa2ac7f197352f4d21580ecb775 /clippy_utils/src/lib.rs | |
| parent | 86092a77b343474562780e2731ee430059e20570 (diff) | |
| parent | 11d22ae7c572ce35923ced63415e95f0a2ab8361 (diff) | |
| download | rust-2a18d124aaea78d2fad8be0135fa8182d40e32fb.tar.gz rust-2a18d124aaea78d2fad8be0135fa8182d40e32fb.zip | |
Auto merge of #97575 - nnethercote:lazify-SourceFile-lines, r=Mark-Simulacrum
Lazify `SourceFile::lines`. `SourceFile::lines` is a big part of metadata. It's stored in a compressed form (a difference list) to save disk space. Decoding it is a big fraction of compile time for very small crates/programs. This commit introduces a new type `SourceFileLines` which has a `Lines` form and a `Diffs` form. The latter is used when the metadata is first read, and it is only decoded into the `Lines` form when line data is actually needed. This avoids the decoding cost for many files, especially in `std`. It's a performance win of up to 15% for tiny crates/programs where metadata decoding is a high part of compilation costs. A `RefCell` is needed because the methods that access lines data (which can trigger decoding) take `&self` rather than `&mut self`. To allow for this, `SourceFile::lines` now takes a `FnMut` that operates on the lines slice rather than returning the lines slice. r? `@Mark-Simulacrum`
Diffstat (limited to 'clippy_utils/src/lib.rs')
| -rw-r--r-- | clippy_utils/src/lib.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index adb37cc9d75..833f8cde63a 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1149,7 +1149,7 @@ fn line_span<T: LintContext>(cx: &T, span: Span) -> Span { let span = original_sp(span, DUMMY_SP); let source_map_and_line = cx.sess().source_map().lookup_line(span.lo()).unwrap(); let line_no = source_map_and_line.line; - let line_start = source_map_and_line.sf.lines[line_no]; + let line_start = source_map_and_line.sf.lines(|lines| lines[line_no]); span.with_lo(line_start) } |
