Skip to content

Commit 748f57c

Browse files
committed
Only clone when required
1 parent 06a883e commit 748f57c

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

crates/rust-analyzer/src/cli/analysis_stats.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,12 +1075,12 @@ fn location_csv_pat(db: &RootDatabase, vfs: &Vfs, sm: &BodySourceMap, pat_id: Pa
10751075
format!("{path},{}:{},{}:{}", start.line + 1, start.col, end.line + 1, end.col)
10761076
}
10771077

1078-
fn expr_syntax_range(
1078+
fn expr_syntax_range<'a>(
10791079
db: &RootDatabase,
1080-
vfs: &Vfs,
1080+
vfs: &'a Vfs,
10811081
sm: &BodySourceMap,
10821082
expr_id: ExprId,
1083-
) -> Option<(VfsPath, LineCol, LineCol)> {
1083+
) -> Option<(&'a VfsPath, LineCol, LineCol)> {
10841084
let src = sm.expr_syntax(expr_id);
10851085
if let Ok(src) = src {
10861086
let root = db.parse_or_expand(src.file_id);
@@ -1096,12 +1096,12 @@ fn expr_syntax_range(
10961096
None
10971097
}
10981098
}
1099-
fn pat_syntax_range(
1099+
fn pat_syntax_range<'a>(
11001100
db: &RootDatabase,
1101-
vfs: &Vfs,
1101+
vfs: &'a Vfs,
11021102
sm: &BodySourceMap,
11031103
pat_id: PatId,
1104-
) -> Option<(VfsPath, LineCol, LineCol)> {
1104+
) -> Option<(&'a VfsPath, LineCol, LineCol)> {
11051105
let src = sm.pat_syntax(pat_id);
11061106
if let Ok(src) = src {
11071107
let root = db.parse_or_expand(src.file_id);

crates/rust-analyzer/src/global_state.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl GlobalState {
297297
let mut bytes = vec![];
298298
let mut modified_rust_files = vec![];
299299
for file in changed_files {
300-
let vfs_path = &vfs.file_path(file.file_id);
300+
let vfs_path = vfs.file_path(file.file_id);
301301
if let Some(path) = vfs_path.as_path() {
302302
let path = path.to_path_buf();
303303
if reload::should_refresh_for_change(&path, file.kind()) {
@@ -481,23 +481,23 @@ impl GlobalStateSnapshot {
481481
}
482482

483483
pub(crate) fn anchored_path(&self, path: &AnchoredPathBuf) -> Url {
484-
let mut base = self.vfs_read().file_path(path.anchor);
484+
let mut base = self.vfs_read().file_path(path.anchor).clone();
485485
base.pop();
486486
let path = base.join(&path.path).unwrap();
487487
let path = path.as_path().unwrap();
488488
url_from_abs_path(path)
489489
}
490490

491491
pub(crate) fn file_id_to_file_path(&self, file_id: FileId) -> vfs::VfsPath {
492-
self.vfs_read().file_path(file_id)
492+
self.vfs_read().file_path(file_id).clone()
493493
}
494494

495495
pub(crate) fn cargo_target_for_crate_root(
496496
&self,
497497
crate_id: CrateId,
498498
) -> Option<(&CargoWorkspace, Target)> {
499499
let file_id = self.analysis.crate_root(crate_id).ok()?;
500-
let path = self.vfs_read().file_path(file_id);
500+
let path = self.vfs_read().file_path(file_id).clone();
501501
let path = path.as_path()?;
502502
self.workspaces.iter().find_map(|ws| match ws {
503503
ProjectWorkspace::Cargo { cargo, .. } => {

crates/rust-analyzer/src/handlers/request.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,7 @@ pub(crate) fn fetch_dependency_list(
20972097
.into_iter()
20982098
.filter_map(|it| {
20992099
let root_file_path = state.file_id_to_file_path(it.root_file_id);
2100-
crate_path(root_file_path).and_then(to_url).map(|path| CrateInfoResult {
2100+
crate_path(&root_file_path).and_then(to_url).map(|path| CrateInfoResult {
21012101
name: it.name,
21022102
version: it.version,
21032103
path,
@@ -2118,7 +2118,7 @@ pub(crate) fn fetch_dependency_list(
21182118
/// An `Option` value representing the path to the directory of the crate with the given
21192119
/// name, if such a crate is found. If no crate with the given name is found, this function
21202120
/// returns `None`.
2121-
fn crate_path(root_file_path: VfsPath) -> Option<VfsPath> {
2121+
fn crate_path(root_file_path: &VfsPath) -> Option<VfsPath> {
21222122
let mut current_dir = root_file_path.parent();
21232123
while let Some(path) = current_dir {
21242124
let cargo_toml_path = path.join("../Cargo.toml")?;

crates/vfs/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ impl Vfs {
163163
/// # Panics
164164
///
165165
/// Panics if the id is not present in the `Vfs`.
166-
pub fn file_path(&self, file_id: FileId) -> VfsPath {
167-
self.interner.lookup(file_id).clone()
166+
pub fn file_path(&self, file_id: FileId) -> &VfsPath {
167+
self.interner.lookup(file_id)
168168
}
169169

170170
/// Returns an iterator over the stored ids and their corresponding paths.

0 commit comments

Comments
 (0)