about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2016-10-10 19:35:22 -0400
committerCorey Farwell <coreyf@rwell.org>2016-10-10 19:35:22 -0400
commita8e257091b4fd77e1b9008c9129635fb6b76ac3d (patch)
tree1a2d6690dc9a00ba36bc0f97a84ac0e5448b0a12
parent3a15475d363d60ba5ab947c6f8595c0a437623b4 (diff)
downloadrust-a8e257091b4fd77e1b9008c9129635fb6b76ac3d.tar.gz
rust-a8e257091b4fd77e1b9008c9129635fb6b76ac3d.zip
Use `Cow` instead of `String` to avoid unnecessary allocations.
-rw-r--r--src/librustc/session/filesearch.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/librustc/session/filesearch.rs b/src/librustc/session/filesearch.rs
index ad10b7e8081..bc38901422c 100644
--- a/src/librustc/session/filesearch.rs
+++ b/src/librustc/session/filesearch.rs
@@ -12,6 +12,7 @@
 
 pub use self::FileMatch::*;
 
+use std::borrow::Cow;
 use std::collections::HashSet;
 use std::env;
 use std::fs;
@@ -123,7 +124,7 @@ impl<'a> FileSearch<'a> {
     // Returns a list of directories where target-specific tool binaries are located.
     pub fn get_tools_search_paths(&self) -> Vec<PathBuf> {
         let mut p = PathBuf::from(self.sysroot);
-        p.push(&find_libdir(self.sysroot));
+        p.push(find_libdir(self.sysroot).as_ref());
         p.push(RUST_LIB_DIR);
         p.push(&self.triple);
         p.push("bin");
@@ -132,7 +133,7 @@ impl<'a> FileSearch<'a> {
 }
 
 pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf {
-    let mut p = PathBuf::from(&find_libdir(sysroot));
+    let mut p = PathBuf::from(find_libdir(sysroot).as_ref());
     assert!(p.is_relative());
     p.push(RUST_LIB_DIR);
     p.push(target_triple);
@@ -166,7 +167,7 @@ pub fn get_or_default_sysroot() -> PathBuf {
 }
 
 // The name of the directory rustc expects libraries to be located.
-fn find_libdir(sysroot: &Path) -> String {
+fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
     // FIXME: This is a quick hack to make the rustc binary able to locate
     // Rust libraries in Linux environments where libraries might be installed
     // to lib64/lib32. This would be more foolproof by basing the sysroot off