summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorBen S <ogham@bsago.me>2015-11-15 15:52:55 +0000
committerBen S <ogham@bsago.me>2015-11-15 15:52:55 +0000
commitca65c981f1eee50344e0df2f2406bce01ed24136 (patch)
treea8ed6e874940216340de9da3077261f9b4d4e984 /src/main.rs
parent2efaf7ec453c817fc3fa5b6dd868f0dac6bcaa40 (diff)
Avoid cloning the file names vector
By taking the file names as a mutable vector, we can avoid having to allocate a new one when it’s empty. The recent changes to Options::getopts have made it more obvious that we could move the same vector out of getopts’s matches, instead of cloning it there.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index cf01ee8..8c4761a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -42,10 +42,14 @@ struct Exa {
}
impl Exa {
- fn run(&mut self, args_file_names: &[String]) {
+ fn run(&mut self, mut args_file_names: Vec<String>) {
let mut files = Vec::new();
let mut dirs = Vec::new();
+ if args_file_names.is_empty() {
+ args_file_names.push(".".to_owned());
+ }
+
for file_name in args_file_names.iter() {
match File::from_path(Path::new(&file_name), None) {
Err(e) => {
@@ -145,7 +149,7 @@ fn main() {
match Options::getopts(&args) {
Ok((options, paths)) => {
let mut exa = Exa { options: options };
- exa.run(&paths);
+ exa.run(paths);
},
Err(e) => {
println!("{}", e);