mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 20:47:46 +00:00
refactor/sort ~ fix cargo clippy
complaint (clippy::needless_borrow)
This commit is contained in:
parent
08713d22ec
commit
39dbcda66e
4 changed files with 16 additions and 16 deletions
|
@ -49,7 +49,7 @@ pub fn check(path: &str, settings: &GlobalSettings) -> i32 {
|
|||
let prev_last = prev_chunk.borrow_lines().last().unwrap();
|
||||
let new_first = chunk.borrow_lines().first().unwrap();
|
||||
|
||||
if compare_by(prev_last, new_first, &settings) == Ordering::Greater {
|
||||
if compare_by(prev_last, new_first, settings) == Ordering::Greater {
|
||||
if !settings.check_silent {
|
||||
println!("sort: {}:{}: disorder: {}", path, line_idx, new_first.line);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ pub fn check(path: &str, settings: &GlobalSettings) -> i32 {
|
|||
|
||||
for (a, b) in chunk.borrow_lines().iter().tuple_windows() {
|
||||
line_idx += 1;
|
||||
if compare_by(a, b, &settings) == Ordering::Greater {
|
||||
if compare_by(a, b, settings) == Ordering::Greater {
|
||||
if !settings.check_silent {
|
||||
println!("sort: {}:{}: disorder: {}", path, line_idx, b.line);
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ pub fn read(
|
|||
if buffer.len() < carry_over.len() {
|
||||
buffer.resize(carry_over.len() + 10 * 1024, 0);
|
||||
}
|
||||
buffer[..carry_over.len()].copy_from_slice(&carry_over);
|
||||
buffer[..carry_over.len()].copy_from_slice(carry_over);
|
||||
let (read, should_continue) = read_to_buffer(
|
||||
file,
|
||||
next_files,
|
||||
|
@ -110,7 +110,7 @@ pub fn read(
|
|||
std::mem::transmute::<Vec<Line<'static>>, Vec<Line<'_>>>(lines)
|
||||
};
|
||||
let read = crash_if_err!(1, std::str::from_utf8(&buf[..read]));
|
||||
parse_lines(read, &mut lines, separator, &settings);
|
||||
parse_lines(read, &mut lines, separator, settings);
|
||||
lines
|
||||
});
|
||||
sender.send(payload).unwrap();
|
||||
|
@ -194,7 +194,7 @@ fn read_to_buffer(
|
|||
continue;
|
||||
}
|
||||
}
|
||||
let mut sep_iter = memchr_iter(separator, &buffer).rev();
|
||||
let mut sep_iter = memchr_iter(separator, buffer).rev();
|
||||
let last_line_end = sep_iter.next();
|
||||
if sep_iter.next().is_some() {
|
||||
// We read enough lines.
|
||||
|
|
|
@ -38,7 +38,7 @@ pub fn custom_str_cmp(
|
|||
) -> Ordering {
|
||||
if !(ignore_case || ignore_non_dictionary || ignore_non_printing) {
|
||||
// There are no custom settings. Fall back to the default strcmp, which is faster.
|
||||
return a.cmp(&b);
|
||||
return a.cmp(b);
|
||||
}
|
||||
let mut a_chars = a
|
||||
.chars()
|
||||
|
|
|
@ -400,9 +400,9 @@ impl<'a> Line<'a> {
|
|||
let line = self.line.replace('\t', ">");
|
||||
writeln!(writer, "{}", line)?;
|
||||
|
||||
let fields = tokenize(&self.line, settings.separator);
|
||||
let fields = tokenize(self.line, settings.separator);
|
||||
for selector in settings.selectors.iter() {
|
||||
let mut selection = selector.get_range(&self.line, Some(&fields));
|
||||
let mut selection = selector.get_range(self.line, Some(&fields));
|
||||
match selector.settings.mode {
|
||||
SortMode::Numeric | SortMode::HumanNumeric => {
|
||||
// find out which range is used for numeric comparisons
|
||||
|
@ -756,7 +756,7 @@ impl FieldSelector {
|
|||
/// Get the selection that corresponds to this selector for the line.
|
||||
/// If needs_fields returned false, tokens may be None.
|
||||
fn get_selection<'a>(&self, line: &'a str, tokens: Option<&[Field]>) -> Selection<'a> {
|
||||
let mut range = &line[self.get_range(&line, tokens)];
|
||||
let mut range = &line[self.get_range(line, tokens)];
|
||||
let num_cache = if self.settings.mode == SortMode::Numeric
|
||||
|| self.settings.mode == SortMode::HumanNumeric
|
||||
{
|
||||
|
@ -846,7 +846,7 @@ impl FieldSelector {
|
|||
|
||||
match resolve_index(line, tokens, &self.from) {
|
||||
Resolution::StartOfChar(from) => {
|
||||
let to = self.to.as_ref().map(|to| resolve_index(line, tokens, &to));
|
||||
let to = self.to.as_ref().map(|to| resolve_index(line, tokens, to));
|
||||
|
||||
let mut range = match to {
|
||||
Some(Resolution::StartOfChar(mut to)) => {
|
||||
|
@ -1257,11 +1257,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
fn output_sorted_lines<'a>(iter: impl Iterator<Item = &'a Line<'a>>, settings: &GlobalSettings) {
|
||||
if settings.unique {
|
||||
print_sorted(
|
||||
iter.dedup_by(|a, b| compare_by(a, b, &settings) == Ordering::Equal),
|
||||
&settings,
|
||||
iter.dedup_by(|a, b| compare_by(a, b, settings) == Ordering::Equal),
|
||||
settings,
|
||||
);
|
||||
} else {
|
||||
print_sorted(iter, &settings);
|
||||
print_sorted(iter, settings);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1277,16 +1277,16 @@ fn exec(files: &[String], settings: &GlobalSettings) -> i32 {
|
|||
} else {
|
||||
let mut lines = files.iter().map(open);
|
||||
|
||||
ext_sort(&mut lines, &settings);
|
||||
ext_sort(&mut lines, settings);
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
fn sort_by<'a>(unsorted: &mut Vec<Line<'a>>, settings: &GlobalSettings) {
|
||||
if settings.stable || settings.unique {
|
||||
unsorted.par_sort_by(|a, b| compare_by(a, b, &settings))
|
||||
unsorted.par_sort_by(|a, b| compare_by(a, b, settings))
|
||||
} else {
|
||||
unsorted.par_sort_unstable_by(|a, b| compare_by(a, b, &settings))
|
||||
unsorted.par_sort_unstable_by(|a, b| compare_by(a, b, settings))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue