diff --git a/src/exec/mod.rs b/src/exec/mod.rs index e6cf9c1fc..0a8569898 100644 --- a/src/exec/mod.rs +++ b/src/exec/mod.rs @@ -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 {