Skip to content

Commit

Permalink
exec/mod.rs: added reason why we sort elements with -X
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoIeni committed Nov 30, 2019
1 parent ceacf9c commit aed7462
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/exec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,20 @@ impl CommandTemplate {
if arg.has_tokens() {
// A single `Tokens` is expected
// So we can directly consume the iterator once and for all

// It would be too expansive to collect all the paths at once, so I take
// only the first ones.
let mut first_paths = take(&mut paths, SORT_THRESHOLD);
has_path = !first_paths.is_empty();

if first_paths.len() < SORT_THRESHOLD {
// I sort the paths because they are not too much
first_paths.sort();
CommandTemplate::add_to_cmd(&mut cmd, arg, &mut first_paths.into_iter());
} else {
CommandTemplate::add_to_cmd(&mut cmd, arg, &mut first_paths.into_iter());

// add remaining paths
CommandTemplate::add_to_cmd(&mut cmd, arg, &mut paths);
}
} else {
Expand Down

0 comments on commit aed7462

Please sign in to comment.