Reduce again the number of match calls (#7815)

- Reduce the number of match calls (see commit messages)
- A few miscellaneous improvements
This commit is contained in:
Hofer-Julian
2023-01-24 12:23:42 +01:00
committed by GitHub
parent 0bb2e47c98
commit 41306aa7e0
49 changed files with 467 additions and 634 deletions

View File

@ -45,16 +45,13 @@ pub fn sort_value_in_place(
insensitive: bool,
natural: bool,
) -> Result<(), ShellError> {
match val {
Value::List { vals, span } => {
sort(vals, sort_columns, *span, insensitive, natural)?;
if !ascending {
vals.reverse();
}
Ok(())
if let Value::List { vals, span } = val {
sort(vals, sort_columns, *span, insensitive, natural)?;
if !ascending {
vals.reverse();
}
_ => Ok(()),
}
Ok(())
}
pub fn sort(
@ -102,10 +99,9 @@ pub fn sort(
let mut vals = vec![];
for item in vec.iter() {
for col in &sort_columns {
let val = match item.get_data_by_key(col) {
Some(v) => v,
None => Value::nothing(Span::unknown()),
};
let val = item
.get_data_by_key(col)
.unwrap_or_else(|| Value::nothing(Span::unknown()));
vals.push(val);
}
}