mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 08:09:23 +02:00
Fix most Clippy performance warnings
command used: cargo clippy -- -W clippy::perf
This commit is contained in:
@ -21,7 +21,7 @@ fn format(input: &str) -> IResult<&str, Vec<FormatCommand>> {
|
||||
let mut loop_input = input;
|
||||
loop {
|
||||
let (input, before) = take_while(|c| c != '{')(loop_input)?;
|
||||
if before.len() > 0 {
|
||||
if !before.is_empty() {
|
||||
output.push(FormatCommand::Text(before.to_string()));
|
||||
}
|
||||
if input != "" {
|
||||
|
@ -90,13 +90,13 @@ impl Inc {
|
||||
}
|
||||
UntaggedValue::Table(values) => {
|
||||
if values.len() == 1 {
|
||||
return Ok(UntaggedValue::Table(vec![self.inc(values[0].clone())?])
|
||||
.into_value(value.tag()));
|
||||
Ok(UntaggedValue::Table(vec![self.inc(values[0].clone())?])
|
||||
.into_value(value.tag()))
|
||||
} else {
|
||||
return Err(ShellError::type_error(
|
||||
Err(ShellError::type_error(
|
||||
"incrementable value",
|
||||
value.type_name().spanned(value.span()),
|
||||
));
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,20 +108,16 @@ impl Inc {
|
||||
&f,
|
||||
Box::new(move |(obj_source, column_path_tried, _)| {
|
||||
match did_you_mean(&obj_source, &column_path_tried) {
|
||||
Some(suggestions) => {
|
||||
return ShellError::labeled_error(
|
||||
"Unknown column",
|
||||
format!("did you mean '{}'?", suggestions[0].1),
|
||||
span_for_spanned_list(fields.iter().map(|p| p.span)),
|
||||
)
|
||||
}
|
||||
None => {
|
||||
return ShellError::labeled_error(
|
||||
"Unknown column",
|
||||
"row does not contain this column",
|
||||
span_for_spanned_list(fields.iter().map(|p| p.span)),
|
||||
)
|
||||
}
|
||||
Some(suggestions) => ShellError::labeled_error(
|
||||
"Unknown column",
|
||||
format!("did you mean '{}'?", suggestions[0].1),
|
||||
span_for_spanned_list(fields.iter().map(|p| p.span)),
|
||||
),
|
||||
None => ShellError::labeled_error(
|
||||
"Unknown column",
|
||||
"row does not contain this column",
|
||||
span_for_spanned_list(fields.iter().map(|p| p.span)),
|
||||
),
|
||||
}
|
||||
}),
|
||||
);
|
||||
@ -133,14 +129,12 @@ impl Inc {
|
||||
&f,
|
||||
replacement.value.clone().into_untagged_value(),
|
||||
) {
|
||||
Some(v) => return Ok(v),
|
||||
None => {
|
||||
return Err(ShellError::labeled_error(
|
||||
"inc could not find field to replace",
|
||||
"column name",
|
||||
value.tag(),
|
||||
))
|
||||
}
|
||||
Some(v) => Ok(v),
|
||||
None => Err(ShellError::labeled_error(
|
||||
"inc could not find field to replace",
|
||||
"column name",
|
||||
value.tag(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
None => Err(ShellError::untagged_runtime_error(
|
||||
@ -201,13 +195,11 @@ impl Plugin for Inc {
|
||||
}
|
||||
|
||||
match &self.error {
|
||||
Some(reason) => {
|
||||
return Err(ShellError::untagged_runtime_error(format!(
|
||||
"{}: {}",
|
||||
reason,
|
||||
Inc::usage()
|
||||
)))
|
||||
}
|
||||
Some(reason) => Err(ShellError::untagged_runtime_error(format!(
|
||||
"{}: {}",
|
||||
reason,
|
||||
Inc::usage()
|
||||
))),
|
||||
None => Ok(vec![]),
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ fn parse(input: &str) -> IResult<&str, Vec<ParseCommand>> {
|
||||
let mut loop_input = input;
|
||||
loop {
|
||||
let (input, before) = take_while(|c| c != '{')(loop_input)?;
|
||||
if before.len() > 0 {
|
||||
if !before.is_empty() {
|
||||
output.push(ParseCommand::Text(before.to_string()));
|
||||
}
|
||||
if input != "" {
|
||||
@ -73,7 +73,7 @@ fn build_regex(commands: &[ParseCommand]) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
output
|
||||
}
|
||||
struct Parse {
|
||||
regex: Regex,
|
||||
|
@ -126,7 +126,7 @@ impl Str {
|
||||
_ => v[0].trim().parse().unwrap(),
|
||||
};
|
||||
let end: usize = match v[1] {
|
||||
"" => usize::max_value().clone(),
|
||||
"" => usize::max_value(),
|
||||
_ => v[1].trim().parse().unwrap(),
|
||||
};
|
||||
if start > end {
|
||||
@ -169,14 +169,12 @@ impl Str {
|
||||
&f,
|
||||
Box::new(move |(obj_source, column_path_tried, error)| {
|
||||
match did_you_mean(&obj_source, &column_path_tried) {
|
||||
Some(suggestions) => {
|
||||
return ShellError::labeled_error(
|
||||
"Unknown column",
|
||||
format!("did you mean '{}'?", suggestions[0].1),
|
||||
span_for_spanned_list(fields.iter().map(|p| p.span)),
|
||||
)
|
||||
}
|
||||
None => return error,
|
||||
Some(suggestions) => ShellError::labeled_error(
|
||||
"Unknown column",
|
||||
format!("did you mean '{}'?", suggestions[0].1),
|
||||
span_for_spanned_list(fields.iter().map(|p| p.span)),
|
||||
),
|
||||
None => error,
|
||||
}
|
||||
}),
|
||||
);
|
||||
@ -188,7 +186,7 @@ impl Str {
|
||||
&f,
|
||||
replacement.value.clone().into_untagged_value(),
|
||||
) {
|
||||
Some(v) => return Ok(v),
|
||||
Some(v) => Ok(v),
|
||||
None => Err(ShellError::labeled_error(
|
||||
"str could not find field to replace",
|
||||
"column name",
|
||||
@ -293,13 +291,11 @@ impl Plugin for Str {
|
||||
}
|
||||
|
||||
match &self.error {
|
||||
Some(reason) => {
|
||||
return Err(ShellError::untagged_runtime_error(format!(
|
||||
"{}: {}",
|
||||
reason,
|
||||
Str::usage()
|
||||
)))
|
||||
}
|
||||
Some(reason) => Err(ShellError::untagged_runtime_error(format!(
|
||||
"{}: {}",
|
||||
reason,
|
||||
Str::usage()
|
||||
))),
|
||||
None => Ok(vec![]),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user