Update clients of path.rs to use new API.

In most cases this involved removing a ~str allocations or clones
(yay), or coercing a ~str to a slice.  In a few places, I had to bind
an intermediate Path (e.g. path.pop() return values), so that it would
live long enough to support the borrowed &str.

And in a few places, where the code was actively using the property
that the old API returned ~str's, I had to put in to_owned() or
clone(); but in those cases, we're trading an allocation within the
path.rs code for one in the client code, so they neutralize each
other.
This commit is contained in:
Felix S. Klock II 2013-09-04 13:10:22 +02:00
parent 0f3c87e26e
commit 7f834c5c07
9 changed files with 27 additions and 23 deletions

View File

@ -307,8 +307,9 @@ pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName {
// Try to elide redundant long paths
fn shorten(path: &Path) -> ~str {
let filename = path.filename();
let dir = path.pop().filename();
fmt!("%s/%s", dir.unwrap_or_default(~""), filename.unwrap_or_default(~""))
let p = path.pop();
let dir = p.filename();
fmt!("%s/%s", dir.unwrap_or_default(""), filename.unwrap_or_default(""))
}
test::DynTestName(fmt!("[%s] %s",

View File

@ -880,7 +880,7 @@ fn _arm_push_aux_shared_library(config: &config, testfile: &Path) {
let dirs = os::list_dir_path(&Path(tstr));
for file in dirs.iter() {
if (file.filetype() == Some(~".so")) {
if (file.filetype() == Some(".so")) {
let copy_result = procsrv::run("", config.adb_path,
[~"push", file.to_str(), config.adb_test_dir.clone()],

View File

@ -162,7 +162,8 @@ fn print_usage(command_string: ~str) -> ValidUsage {
fn cmd_test(args: &[~str]) -> ValidUsage {
match args {
[ref filename] => {
let test_exec = Path(*filename).filestem().unwrap() + "test~";
let p = Path(*filename);
let test_exec = p.filestem().unwrap() + "test~";
invoke("rustc", &[~"--test", filename.to_owned(),
~"-o", test_exec.to_owned()], rustc::main_args);
let exit_code = run::process_status(~"./" + test_exec, []);
@ -175,7 +176,8 @@ fn cmd_test(args: &[~str]) -> ValidUsage {
fn cmd_run(args: &[~str]) -> ValidUsage {
match args {
[ref filename, ..prog_args] => {
let exec = Path(*filename).filestem().unwrap() + "~";
let p = Path(*filename);
let exec = p.filestem().unwrap() + "~";
invoke("rustc", &[filename.to_owned(), ~"-o", exec.to_owned()],
rustc::main_args);
let exit_code = run::process_status(~"./"+exec, prog_args);

View File

@ -948,13 +948,13 @@ fn unlib(config: @session::config, stem: ~str) -> ~str {
let cstore = sess.cstore;
let r = cstore::get_used_crate_files(cstore);
for cratepath in r.iter() {
if cratepath.filetype() == Some(~".rlib") {
if cratepath.filetype() == Some(".rlib") {
args.push(cratepath.to_str());
loop;
}
let dir = cratepath.dirname();
if dir != ~"" { args.push(~"-L" + dir); }
let libarg = unlib(sess.targ_cfg, cratepath.filestem().unwrap());
let libarg = unlib(sess.targ_cfg, cratepath.filestem().unwrap().to_owned());
args.push(~"-l" + libarg);
}

View File

@ -19,7 +19,8 @@ pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool {
for p in workspaces.iter() {
let binfiles = os::list_dir(&p.push("bin"));
for exec in binfiles.iter() {
let exec_path = Path(*exec).filestem();
let p = Path(*exec);
let exec_path = p.filestem();
do exec_path.iter().advance |s| {
f(&PkgId::new(*s))
};
@ -49,8 +50,8 @@ pub fn has_library(p: &Path) -> Option<~str> {
let files = os::list_dir(p);
for q in files.iter() {
let as_path = Path(*q);
if as_path.filetype() == Some(os::consts::DLL_SUFFIX.to_owned()) {
let stuff : ~str = as_path.filestem().expect("has_library: weird path");
if as_path.filetype() == Some(os::consts::DLL_SUFFIX) {
let stuff : &str = as_path.filestem().expect("has_library: weird path");
let mut stuff2 = stuff.split_str_iter(&"-");
let stuff3: ~[&str] = stuff2.collect();
// argh

View File

@ -68,7 +68,7 @@ pub fn new(s: &str) -> PkgId {
if path.components.len() < 1 {
return cond.raise((path, ~"0-length pkgid"));
}
let short_name = path.clone().filestem().expect(fmt!("Strange path! %s", s));
let short_name = path.filestem().expect(fmt!("Strange path! %s", s));
let version = match given_version {
Some(v) => v,
@ -83,8 +83,8 @@ pub fn new(s: &str) -> PkgId {
debug!("path = %s", path.to_str());
PkgId {
path: path,
short_name: short_name,
path: path.clone(),
short_name: short_name.to_owned(),
version: version
}
}

View File

@ -118,7 +118,7 @@ pub fn fetch_git(&self) -> Option<Path> {
return Some(local);
}
if (self.id.path.clone()).components().len() < 2 {
if self.id.path.components().len() < 2 {
// If a non-URL, don't bother trying to fetch
return None;
}
@ -156,7 +156,7 @@ pub fn package_script_option(&self, cwd: &Path) -> Option<Path> {
/// True if the given path's stem is self's pkg ID's stem
fn stem_matches(&self, p: &Path) -> bool {
p.filestem().map_default(false, |p| { p == &self.id.short_name })
p.filestem().map_default(false, |p| { p == &self.id.short_name.as_slice() })
}
fn push_crate(cs: &mut ~[Crate], prefix: uint, p: &Path) {
@ -181,10 +181,10 @@ pub fn find_crates(&mut self, cx: &Ctx) {
do os::walk_dir(&dir) |pth| {
let maybe_known_crate_set = match pth.filename() {
Some(filename) => match filename {
~"lib.rs" => Some(&mut self.libs),
~"main.rs" => Some(&mut self.mains),
~"test.rs" => Some(&mut self.tests),
~"bench.rs" => Some(&mut self.benchs),
"lib.rs" => Some(&mut self.libs),
"main.rs" => Some(&mut self.mains),
"test.rs" => Some(&mut self.tests),
"bench.rs" => Some(&mut self.benchs),
_ => None
},
_ => None

View File

@ -234,14 +234,14 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
Some(j) => {
debug!("Maybe %s equals %s", f_name.slice(0, j), lib_prefix);
if f_name.slice(0, j) == lib_prefix {
result_filename = Some(p_path);
result_filename = Some(p_path.clone());
}
break;
}
None => break
}
}
_ => { f_name = f_name.slice(0, i).to_owned(); }
_ => { f_name = f_name.slice(0, i); }
}
}
None => break

View File

@ -396,7 +396,7 @@ fn touch_source_file(workspace: &Path, pkgid: &PkgId) {
let pkg_src_dir = workspace.push("src").push(pkgid.to_str());
let contents = os::list_dir_path(&pkg_src_dir);
for p in contents.iter() {
if p.filetype() == Some(~".rs") {
if p.filetype() == Some(".rs") {
// should be able to do this w/o a process
if run::process_output("touch", [p.to_str()]).status != 0 {
let _ = cond.raise((pkg_src_dir.clone(), ~"Bad path"));
@ -413,7 +413,7 @@ fn frob_source_file(workspace: &Path, pkgid: &PkgId) {
let contents = os::list_dir_path(&pkg_src_dir);
let mut maybe_p = None;
for p in contents.iter() {
if p.filetype() == Some(~".rs") {
if p.filetype() == Some(".rs") {
maybe_p = Some(p);
break;
}