about summary refs log tree commit diff
path: root/compiler/rustc_span/src
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2025-08-19 19:45:37 +0800
committerGitHub <noreply@github.com>2025-08-19 19:45:37 +0800
commit3134f22d8b8cfef148add9e9a14522d622fd6a7f (patch)
tree202a302a239bc3dbd3e359d5570bf29877863791 /compiler/rustc_span/src
parent758866d48b4a715e6db9893649407cdcaea5f713 (diff)
parenta84373085e184460c3cbaefaad0339723af4944e (diff)
downloadrust-3134f22d8b8cfef148add9e9a14522d622fd6a7f.tar.gz
rust-3134f22d8b8cfef148add9e9a14522d622fd6a7f.zip
Rollup merge of #145505 - cjgillot:tweak-span-cache, r=petrochenkov
Simplify span caches

Split from https://github.com/rust-lang/rust/pull/143882

r? `@petrochenkov`
Diffstat (limited to 'compiler/rustc_span/src')
-rw-r--r--compiler/rustc_span/src/caching_source_map_view.rs30
1 files changed, 14 insertions, 16 deletions
diff --git a/compiler/rustc_span/src/caching_source_map_view.rs b/compiler/rustc_span/src/caching_source_map_view.rs
index a887b50ec1e..41cfaa3ee34 100644
--- a/compiler/rustc_span/src/caching_source_map_view.rs
+++ b/compiler/rustc_span/src/caching_source_map_view.rs
@@ -123,27 +123,25 @@ impl<'sm> CachingSourceMapView<'sm> {
 
         if lo_cache_idx != -1 && hi_cache_idx != -1 {
             // Cache hit for span lo and hi. Check if they belong to the same file.
-            let result = {
-                let lo = &self.line_cache[lo_cache_idx as usize];
-                let hi = &self.line_cache[hi_cache_idx as usize];
+            let lo_file_index = self.line_cache[lo_cache_idx as usize].file_index;
+            let hi_file_index = self.line_cache[hi_cache_idx as usize].file_index;
 
-                if lo.file_index != hi.file_index {
-                    return None;
-                }
-
-                (
-                    lo.file.stable_id,
-                    lo.line_number,
-                    span_data.lo - lo.line.start,
-                    hi.line_number,
-                    span_data.hi - hi.line.start,
-                )
-            };
+            if lo_file_index != hi_file_index {
+                return None;
+            }
 
             self.line_cache[lo_cache_idx as usize].touch(self.time_stamp);
             self.line_cache[hi_cache_idx as usize].touch(self.time_stamp);
 
-            return Some(result);
+            let lo = &self.line_cache[lo_cache_idx as usize];
+            let hi = &self.line_cache[hi_cache_idx as usize];
+            return Some((
+                lo.file.stable_id,
+                lo.line_number,
+                span_data.lo - lo.line.start,
+                hi.line_number,
+                span_data.hi - hi.line.start,
+            ));
         }
 
         // No cache hit or cache hit for only one of span lo and hi.