提交 ca65c981 编写于 作者: B Ben S

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.
上级 2efaf7ec
......@@ -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);
......
......@@ -83,15 +83,8 @@ impl Options {
return Err(Misfire::Version);
}
let path_strs = if matches.free.is_empty() {
vec![ ".".to_string() ]
}
else {
matches.free.clone()
};
let options = try!(Options::deduce(&matches));
Ok((options, path_strs))
Ok((options, matches.free))
}
/// Whether the View specified in this set of options includes a Git
......@@ -611,7 +604,7 @@ mod test {
#[test]
fn no_args() {
let args = Options::getopts(&[]).unwrap().1;
assert_eq!(args, vec![ ".".to_string() ])
assert!(args.is_empty()); // Listing the `.` directory is done in main.rs
}
#[test]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册