Skip to content

Commit 7f834c5

Browse files
committed
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.
1 parent 0f3c87e commit 7f834c5

File tree

9 files changed

+27
-23
lines changed

9 files changed

+27
-23
lines changed

src/compiletest/compiletest.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName {
307307
// Try to elide redundant long paths
308308
fn shorten(path: &Path) -> ~str {
309309
let filename = path.filename();
310-
let dir = path.pop().filename();
311-
fmt!("%s/%s", dir.unwrap_or_default(~""), filename.unwrap_or_default(~""))
310+
let p = path.pop();
311+
let dir = p.filename();
312+
fmt!("%s/%s", dir.unwrap_or_default(""), filename.unwrap_or_default(""))
312313
}
313314

314315
test::DynTestName(fmt!("[%s] %s",

src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ fn _arm_push_aux_shared_library(config: &config, testfile: &Path) {
880880
let dirs = os::list_dir_path(&Path(tstr));
881881
for file in dirs.iter() {
882882

883-
if (file.filetype() == Some(~".so")) {
883+
if (file.filetype() == Some(".so")) {
884884

885885
let copy_result = procsrv::run("", config.adb_path,
886886
[~"push", file.to_str(), config.adb_test_dir.clone()],

src/librust/rust.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ fn cmd_help(args: &[~str]) -> ValidUsage {
162162
fn cmd_test(args: &[~str]) -> ValidUsage {
163163
match args {
164164
[ref filename] => {
165-
let test_exec = Path(*filename).filestem().unwrap() + "test~";
165+
let p = Path(*filename);
166+
let test_exec = p.filestem().unwrap() + "test~";
166167
invoke("rustc", &[~"--test", filename.to_owned(),
167168
~"-o", test_exec.to_owned()], rustc::main_args);
168169
let exit_code = run::process_status(~"./" + test_exec, []);
@@ -175,7 +176,8 @@ fn cmd_test(args: &[~str]) -> ValidUsage {
175176
fn cmd_run(args: &[~str]) -> ValidUsage {
176177
match args {
177178
[ref filename, ..prog_args] => {
178-
let exec = Path(*filename).filestem().unwrap() + "~";
179+
let p = Path(*filename);
180+
let exec = p.filestem().unwrap() + "~";
179181
invoke("rustc", &[filename.to_owned(), ~"-o", exec.to_owned()],
180182
rustc::main_args);
181183
let exit_code = run::process_status(~"./"+exec, prog_args);

src/librustc/back/link.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,13 +948,13 @@ pub fn link_args(sess: Session,
948948
let cstore = sess.cstore;
949949
let r = cstore::get_used_crate_files(cstore);
950950
for cratepath in r.iter() {
951-
if cratepath.filetype() == Some(~".rlib") {
951+
if cratepath.filetype() == Some(".rlib") {
952952
args.push(cratepath.to_str());
953953
loop;
954954
}
955955
let dir = cratepath.dirname();
956956
if dir != ~"" { args.push(~"-L" + dir); }
957-
let libarg = unlib(sess.targ_cfg, cratepath.filestem().unwrap());
957+
let libarg = unlib(sess.targ_cfg, cratepath.filestem().unwrap().to_owned());
958958
args.push(~"-l" + libarg);
959959
}
960960

src/librustpkg/installed_packages.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool {
1919
for p in workspaces.iter() {
2020
let binfiles = os::list_dir(&p.push("bin"));
2121
for exec in binfiles.iter() {
22-
let exec_path = Path(*exec).filestem();
22+
let p = Path(*exec);
23+
let exec_path = p.filestem();
2324
do exec_path.iter().advance |s| {
2425
f(&PkgId::new(*s))
2526
};
@@ -49,8 +50,8 @@ pub fn has_library(p: &Path) -> Option<~str> {
4950
let files = os::list_dir(p);
5051
for q in files.iter() {
5152
let as_path = Path(*q);
52-
if as_path.filetype() == Some(os::consts::DLL_SUFFIX.to_owned()) {
53-
let stuff : ~str = as_path.filestem().expect("has_library: weird path");
53+
if as_path.filetype() == Some(os::consts::DLL_SUFFIX) {
54+
let stuff : &str = as_path.filestem().expect("has_library: weird path");
5455
let mut stuff2 = stuff.split_str_iter(&"-");
5556
let stuff3: ~[&str] = stuff2.collect();
5657
// argh

src/librustpkg/package_id.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl PkgId {
6868
if path.components.len() < 1 {
6969
return cond.raise((path, ~"0-length pkgid"));
7070
}
71-
let short_name = path.clone().filestem().expect(fmt!("Strange path! %s", s));
71+
let short_name = path.filestem().expect(fmt!("Strange path! %s", s));
7272

7373
let version = match given_version {
7474
Some(v) => v,
@@ -83,8 +83,8 @@ impl PkgId {
8383

8484
debug!("path = %s", path.to_str());
8585
PkgId {
86-
path: path,
87-
short_name: short_name,
86+
path: path.clone(),
87+
short_name: short_name.to_owned(),
8888
version: version
8989
}
9090
}

src/librustpkg/package_source.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl PkgSrc {
118118
return Some(local);
119119
}
120120

121-
if (self.id.path.clone()).components().len() < 2 {
121+
if self.id.path.components().len() < 2 {
122122
// If a non-URL, don't bother trying to fetch
123123
return None;
124124
}
@@ -156,7 +156,7 @@ impl PkgSrc {
156156

157157
/// True if the given path's stem is self's pkg ID's stem
158158
fn stem_matches(&self, p: &Path) -> bool {
159-
p.filestem().map_default(false, |p| { p == &self.id.short_name })
159+
p.filestem().map_default(false, |p| { p == &self.id.short_name.as_slice() })
160160
}
161161

162162
fn push_crate(cs: &mut ~[Crate], prefix: uint, p: &Path) {
@@ -181,10 +181,10 @@ impl PkgSrc {
181181
do os::walk_dir(&dir) |pth| {
182182
let maybe_known_crate_set = match pth.filename() {
183183
Some(filename) => match filename {
184-
~"lib.rs" => Some(&mut self.libs),
185-
~"main.rs" => Some(&mut self.mains),
186-
~"test.rs" => Some(&mut self.tests),
187-
~"bench.rs" => Some(&mut self.benchs),
184+
"lib.rs" => Some(&mut self.libs),
185+
"main.rs" => Some(&mut self.mains),
186+
"test.rs" => Some(&mut self.tests),
187+
"bench.rs" => Some(&mut self.benchs),
188188
_ => None
189189
},
190190
_ => None

src/librustpkg/path_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,14 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
234234
Some(j) => {
235235
debug!("Maybe %s equals %s", f_name.slice(0, j), lib_prefix);
236236
if f_name.slice(0, j) == lib_prefix {
237-
result_filename = Some(p_path);
237+
result_filename = Some(p_path.clone());
238238
}
239239
break;
240240
}
241241
None => break
242242
}
243243
}
244-
_ => { f_name = f_name.slice(0, i).to_owned(); }
244+
_ => { f_name = f_name.slice(0, i); }
245245
}
246246
}
247247
None => break

src/librustpkg/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ fn touch_source_file(workspace: &Path, pkgid: &PkgId) {
396396
let pkg_src_dir = workspace.push("src").push(pkgid.to_str());
397397
let contents = os::list_dir_path(&pkg_src_dir);
398398
for p in contents.iter() {
399-
if p.filetype() == Some(~".rs") {
399+
if p.filetype() == Some(".rs") {
400400
// should be able to do this w/o a process
401401
if run::process_output("touch", [p.to_str()]).status != 0 {
402402
let _ = cond.raise((pkg_src_dir.clone(), ~"Bad path"));
@@ -413,7 +413,7 @@ fn frob_source_file(workspace: &Path, pkgid: &PkgId) {
413413
let contents = os::list_dir_path(&pkg_src_dir);
414414
let mut maybe_p = None;
415415
for p in contents.iter() {
416-
if p.filetype() == Some(~".rs") {
416+
if p.filetype() == Some(".rs") {
417417
maybe_p = Some(p);
418418
break;
419419
}

0 commit comments

Comments
 (0)