mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 13:07:46 +00:00
uucore: remove unneccessary closues
This adresses only those where the fix has less letters than the original and is "trivial" (There are possibly a lot of std::string::ToString::to_string and those may only be shortened with additional imports). Found with clippy::redundant-closure-for-method-calls
This commit is contained in:
parent
bd43a7ed99
commit
9906e66096
6 changed files with 11 additions and 15 deletions
|
@ -53,11 +53,7 @@ impl<'a> Iterator for WhitespaceSplitter<'a> {
|
||||||
.unwrap_or(haystack.len()),
|
.unwrap_or(haystack.len()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (field, rest) = field.split_at(
|
let (field, rest) = field.split_at(field.find(char::is_whitespace).unwrap_or(field.len()));
|
||||||
field
|
|
||||||
.find(|c: char| c.is_whitespace())
|
|
||||||
.unwrap_or(field.len()),
|
|
||||||
);
|
|
||||||
|
|
||||||
self.s = if rest.is_empty() { None } else { Some(rest) };
|
self.s = if rest.is_empty() { None } else { Some(rest) };
|
||||||
|
|
||||||
|
@ -107,7 +103,7 @@ fn parse_implicit_precision(s: &str) -> usize {
|
||||||
match s.split_once('.') {
|
match s.split_once('.') {
|
||||||
Some((_, decimal_part)) => decimal_part
|
Some((_, decimal_part)) => decimal_part
|
||||||
.chars()
|
.chars()
|
||||||
.take_while(|c| c.is_ascii_digit())
|
.take_while(char::is_ascii_digit)
|
||||||
.count(),
|
.count(),
|
||||||
None => 0,
|
None => 0,
|
||||||
}
|
}
|
||||||
|
|
|
@ -221,8 +221,8 @@ pub fn numeric_str_cmp((a, a_info): (&str, &NumInfo), (b, b_info): (&str, &NumIn
|
||||||
a_info.exponent.cmp(&b_info.exponent)
|
a_info.exponent.cmp(&b_info.exponent)
|
||||||
} else {
|
} else {
|
||||||
// walk the characters from the front until we find a difference
|
// walk the characters from the front until we find a difference
|
||||||
let mut a_chars = a.chars().filter(|c| c.is_ascii_digit());
|
let mut a_chars = a.chars().filter(char::is_ascii_digit);
|
||||||
let mut b_chars = b.chars().filter(|c| c.is_ascii_digit());
|
let mut b_chars = b.chars().filter(char::is_ascii_digit);
|
||||||
loop {
|
loop {
|
||||||
let a_next = a_chars.next();
|
let a_next = a_chars.next();
|
||||||
let b_next = b_chars.next();
|
let b_next = b_chars.next();
|
||||||
|
|
|
@ -985,7 +985,7 @@ impl FieldSelector {
|
||||||
let mut range = match to {
|
let mut range = match to {
|
||||||
Some(Resolution::StartOfChar(mut to)) => {
|
Some(Resolution::StartOfChar(mut to)) => {
|
||||||
// We need to include the character at `to`.
|
// We need to include the character at `to`.
|
||||||
to += line[to..].chars().next().map_or(1, |c| c.len_utf8());
|
to += line[to..].chars().next().map_or(1, char::len_utf8);
|
||||||
from..to
|
from..to
|
||||||
}
|
}
|
||||||
Some(Resolution::EndOfChar(to)) => from..to,
|
Some(Resolution::EndOfChar(to)) => from..to,
|
||||||
|
|
|
@ -160,7 +160,7 @@ impl Uniq {
|
||||||
|
|
||||||
// fast path: avoid skipping
|
// fast path: avoid skipping
|
||||||
if self.ignore_case && slice_start == 0 && slice_stop == len {
|
if self.ignore_case && slice_start == 0 && slice_stop == len {
|
||||||
return closure(&mut fields_to_check.chars().flat_map(|c| c.to_uppercase()));
|
return closure(&mut fields_to_check.chars().flat_map(char::to_uppercase));
|
||||||
}
|
}
|
||||||
|
|
||||||
// fast path: we can avoid mapping chars to upper-case, if we don't want to ignore the case
|
// fast path: we can avoid mapping chars to upper-case, if we don't want to ignore the case
|
||||||
|
@ -173,7 +173,7 @@ impl Uniq {
|
||||||
.chars()
|
.chars()
|
||||||
.skip(slice_start)
|
.skip(slice_start)
|
||||||
.take(slice_stop)
|
.take(slice_stop)
|
||||||
.flat_map(|c| c.to_uppercase()),
|
.flat_map(char::to_uppercase),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
closure(&mut fields_to_check.chars())
|
closure(&mut fields_to_check.chars())
|
||||||
|
|
|
@ -190,7 +190,7 @@ impl<'a> Inputs<'a> {
|
||||||
|
|
||||||
// The 1-based index of each yielded item must be tracked for error reporting.
|
// The 1-based index of each yielded item must be tracked for error reporting.
|
||||||
let mut with_idx = base.enumerate().map(|(i, v)| (i + 1, v));
|
let mut with_idx = base.enumerate().map(|(i, v)| (i + 1, v));
|
||||||
let files0_from_path = settings.files0_from.as_ref().map(|p| p.as_borrowed());
|
let files0_from_path = settings.files0_from.as_ref().map(Input::as_borrowed);
|
||||||
|
|
||||||
let iter = iter::from_fn(move || {
|
let iter = iter::from_fn(move || {
|
||||||
let (idx, next) = with_idx.next()?;
|
let (idx, next) = with_idx.next()?;
|
||||||
|
|
|
@ -90,9 +90,9 @@ impl<'parser> Parser<'parser> {
|
||||||
NumberSystem::Hexadecimal => size
|
NumberSystem::Hexadecimal => size
|
||||||
.chars()
|
.chars()
|
||||||
.take(2)
|
.take(2)
|
||||||
.chain(size.chars().skip(2).take_while(|c| c.is_ascii_hexdigit()))
|
.chain(size.chars().skip(2).take_while(char::is_ascii_hexdigit))
|
||||||
.collect(),
|
.collect(),
|
||||||
_ => size.chars().take_while(|c| c.is_ascii_digit()).collect(),
|
_ => size.chars().take_while(char::is_ascii_digit).collect(),
|
||||||
};
|
};
|
||||||
let mut unit: &str = &size[numeric_string.len()..];
|
let mut unit: &str = &size[numeric_string.len()..];
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ impl<'parser> Parser<'parser> {
|
||||||
|
|
||||||
let num_digits: usize = size
|
let num_digits: usize = size
|
||||||
.chars()
|
.chars()
|
||||||
.take_while(|c| c.is_ascii_digit())
|
.take_while(char::is_ascii_digit)
|
||||||
.collect::<String>()
|
.collect::<String>()
|
||||||
.len();
|
.len();
|
||||||
let all_zeros = size.chars().all(|c| c == '0');
|
let all_zeros = size.chars().all(|c| c == '0');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue