Skip to content

Commit a8e2570

Browse files
committed
Use Cow instead of String to avoid unnecessary allocations.
1 parent 3a15475 commit a8e2570

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/librustc/session/filesearch.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
pub use self::FileMatch::*;
1414

15+
use std::borrow::Cow;
1516
use std::collections::HashSet;
1617
use std::env;
1718
use std::fs;
@@ -123,7 +124,7 @@ impl<'a> FileSearch<'a> {
123124
// Returns a list of directories where target-specific tool binaries are located.
124125
pub fn get_tools_search_paths(&self) -> Vec<PathBuf> {
125126
let mut p = PathBuf::from(self.sysroot);
126-
p.push(&find_libdir(self.sysroot));
127+
p.push(find_libdir(self.sysroot).as_ref());
127128
p.push(RUST_LIB_DIR);
128129
p.push(&self.triple);
129130
p.push("bin");
@@ -132,7 +133,7 @@ impl<'a> FileSearch<'a> {
132133
}
133134

134135
pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf {
135-
let mut p = PathBuf::from(&find_libdir(sysroot));
136+
let mut p = PathBuf::from(find_libdir(sysroot).as_ref());
136137
assert!(p.is_relative());
137138
p.push(RUST_LIB_DIR);
138139
p.push(target_triple);
@@ -166,7 +167,7 @@ pub fn get_or_default_sysroot() -> PathBuf {
166167
}
167168

168169
// The name of the directory rustc expects libraries to be located.
169-
fn find_libdir(sysroot: &Path) -> String {
170+
fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
170171
// FIXME: This is a quick hack to make the rustc binary able to locate
171172
// Rust libraries in Linux environments where libraries might be installed
172173
// to lib64/lib32. This would be more foolproof by basing the sysroot off

0 commit comments

Comments
 (0)