Skip to content

Commit 082a88e

Browse files
committed
Merge pull request #4032 from catamorphism/getopts
[libstd] getopts, now with fewer copies
2 parents 19f5f91 + f74fe89 commit 082a88e

File tree

10 files changed

+68
-53
lines changed

10 files changed

+68
-53
lines changed

src/compiletest/compiletest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ fn parse_config(args: ~[~str]) -> config {
3535
assert (vec::is_not_empty(args));
3636
let args_ = vec::tail(args);
3737
let matches =
38-
match getopts::getopts(args_, opts) {
38+
&match getopts::getopts(args_, opts) {
3939
Ok(m) => m,
4040
Err(f) => fail getopts::fail_str(f)
4141
};
4242

43-
fn opt_path(m: getopts::Matches, nm: ~str) -> Path {
43+
fn opt_path(m: &getopts::Matches, nm: ~str) -> Path {
4444
Path(getopts::opt_str(m, nm))
4545
}
4646

src/libcargo/cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ fn load_source_packages(c: &Cargo, src: @Source) {
661661
}
662662

663663
fn build_cargo_options(argv: ~[~str]) -> Options {
664-
let matches = match getopts::getopts(argv, opts()) {
664+
let matches = &match getopts::getopts(argv, opts()) {
665665
result::Ok(m) => m,
666666
result::Err(f) => {
667667
fail fmt!("%s", getopts::fail_str(f));

src/librustc/driver/driver.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ fn host_triple() -> ~str {
458458
}
459459

460460
fn build_session_options(binary: ~str,
461-
matches: getopts::Matches,
461+
matches: &getopts::Matches,
462462
demitter: diagnostic::emitter) -> @session::options {
463463
let crate_type = if opt_present(matches, ~"lib") {
464464
session::lib_crate
@@ -807,7 +807,7 @@ mod test {
807807
#[test]
808808
fn test_switch_implies_cfg_test() {
809809
let matches =
810-
match getopts(~[~"--test"], optgroups()) {
810+
&match getopts(~[~"--test"], optgroups()) {
811811
Ok(m) => m,
812812
Err(f) => fail ~"test_switch_implies_cfg_test: " +
813813
getopts::fail_str(f)
@@ -824,7 +824,7 @@ mod test {
824824
#[test]
825825
fn test_switch_implies_cfg_test_unless_cfg_test() {
826826
let matches =
827-
match getopts(~[~"--test", ~"--cfg=test"], optgroups()) {
827+
&match getopts(~[~"--test", ~"--cfg=test"], optgroups()) {
828828
Ok(m) => m,
829829
Err(f) => {
830830
fail ~"test_switch_implies_cfg_test_unless_cfg_test: " +

src/librustc/middle/typeck/infer/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct RH {
3434
}
3535

3636
fn setup_env(test_name: &str, source_string: &str) -> Env {
37-
let matches = getopts(~[~"-Z", ~"verbose"], optgroups()).get();
37+
let matches = &getopts(~[~"-Z", ~"verbose"], optgroups()).get();
3838
let sessopts = build_session_options(~"rustc", matches, diagnostic::emit);
3939
let sess = build_session(sessopts, diagnostic::emit);
4040
let cfg = build_configuration(sess, ~"whatever", str_input(~""));

src/librustc/rustc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn run_compiler(args: &~[~str], demitter: diagnostic::emitter) {
8585
if args.is_empty() { usage(binary); return; }
8686

8787
let matches =
88-
match getopts::groups::getopts(args, optgroups()) {
88+
&match getopts::groups::getopts(args, optgroups()) {
8989
Ok(m) => m,
9090
Err(f) => {
9191
early_error(demitter, getopts::fail_str(f))

src/librustdoc/config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ fn parse_config_(
128128
args: &[~str],
129129
+program_output: ProgramOutput
130130
) -> Result<Config, ~str> {
131-
let args = vec::tail(args);
131+
let args = args.tail();
132132
let opts = vec::unzip(opts()).first();
133133
match getopts::getopts(args, opts) {
134134
result::Ok(matches) => {
135-
if vec::len(matches.free) == 1u {
135+
if matches.free.len() == 1 {
136136
let input_crate = Path(vec::head(matches.free));
137-
config_from_opts(&input_crate, matches, move program_output)
138-
} else if vec::is_empty(matches.free) {
137+
config_from_opts(&input_crate, &matches, move program_output)
138+
} else if matches.free.is_empty() {
139139
result::Err(~"no crates specified")
140140
} else {
141141
result::Err(~"multiple crates specified")
@@ -149,7 +149,7 @@ fn parse_config_(
149149

150150
fn config_from_opts(
151151
input_crate: &Path,
152-
+matches: getopts::Matches,
152+
matches: &getopts::Matches,
153153
+program_output: ProgramOutput
154154
) -> Result<Config, ~str> {
155155

0 commit comments

Comments
 (0)