Skip to content

Commit d095a30

Browse files
committed
Avoid allocations on every call to Path::join
1 parent 51712cc commit d095a30

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/project.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use glob::glob;
33
use serde::{Deserialize, Serialize};
44
use std::env;
55
use std::error::Error;
6-
use std::path::{Path, PathBuf};
6+
use std::path::PathBuf;
77
use std::process::Command;
88

99
/// Contains the structure of resulting rust-project.json file
@@ -45,15 +45,9 @@ impl RustAnalyzerProject {
4545

4646
println!("Determined toolchain: {toolchain}\n");
4747

48-
let Ok(sysroot_src) = Path::new(toolchain)
49-
.join("lib")
50-
.join("rustlib")
51-
.join("src")
52-
.join("rust")
53-
.join("library")
54-
.into_os_string()
55-
.into_string()
56-
else {
48+
let mut sysroot_src = PathBuf::with_capacity(256);
49+
sysroot_src.extend([toolchain, "lib", "rustlib", "src", "rust", "library"]);
50+
let Ok(sysroot_src) = sysroot_src.into_os_string().into_string() else {
5751
bail!("The sysroot path is invalid UTF8");
5852
};
5953

0 commit comments

Comments
 (0)