mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 13:37:48 +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 prev_last = prev_chunk.borrow_lines().last().unwrap();
|
||||||
let new_first = chunk.borrow_lines().first().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 {
|
if !settings.check_silent {
|
||||||
println!("sort: {}:{}: disorder: {}", path, line_idx, new_first.line);
|
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() {
|
for (a, b) in chunk.borrow_lines().iter().tuple_windows() {
|
||||||
line_idx += 1;
|
line_idx += 1;
|
||||||
if compare_by(a, b, &settings) == Ordering::Greater {
|
if compare_by(a, b, settings) == Ordering::Greater {
|
||||||
if !settings.check_silent {
|
if !settings.check_silent {
|
||||||
println!("sort: {}:{}: disorder: {}", path, line_idx, b.line);
|
println!("sort: {}:{}: disorder: {}", path, line_idx, b.line);
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ pub fn read(
|
||||||
if buffer.len() < carry_over.len() {
|
if buffer.len() < carry_over.len() {
|
||||||
buffer.resize(carry_over.len() + 10 * 1024, 0);
|
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(
|
let (read, should_continue) = read_to_buffer(
|
||||||
file,
|
file,
|
||||||
next_files,
|
next_files,
|
||||||
|
@ -110,7 +110,7 @@ pub fn read(
|
||||||
std::mem::transmute::<Vec<Line<'static>>, Vec<Line<'_>>>(lines)
|
std::mem::transmute::<Vec<Line<'static>>, Vec<Line<'_>>>(lines)
|
||||||
};
|
};
|
||||||
let read = crash_if_err!(1, std::str::from_utf8(&buf[..read]));
|
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
|
lines
|
||||||
});
|
});
|
||||||
sender.send(payload).unwrap();
|
sender.send(payload).unwrap();
|
||||||
|
@ -194,7 +194,7 @@ fn read_to_buffer(
|
||||||
continue;
|
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();
|
let last_line_end = sep_iter.next();
|
||||||
if sep_iter.next().is_some() {
|
if sep_iter.next().is_some() {
|
||||||
// We read enough lines.
|
// We read enough lines.
|
||||||
|
|
|
@ -38,7 +38,7 @@ pub fn custom_str_cmp(
|
||||||
) -> Ordering {
|
) -> Ordering {
|
||||||
if !(ignore_case || ignore_non_dictionary || ignore_non_printing) {
|
if !(ignore_case || ignore_non_dictionary || ignore_non_printing) {
|
||||||
// There are no custom settings. Fall back to the default strcmp, which is faster.
|
// 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
|
let mut a_chars = a
|
||||||
.chars()
|
.chars()
|
||||||
|
|
|
@ -400,9 +400,9 @@ impl<'a> Line<'a> {
|
||||||
let line = self.line.replace('\t', ">");
|
let line = self.line.replace('\t', ">");
|
||||||
writeln!(writer, "{}", line)?;
|
writeln!(writer, "{}", line)?;
|
||||||
|
|
||||||
let fields = tokenize(&self.line, settings.separator);
|
let fields = tokenize(self.line, settings.separator);
|
||||||
for selector in settings.selectors.iter() {
|
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 {
|
match selector.settings.mode {
|
||||||
SortMode::Numeric | SortMode::HumanNumeric => {
|
SortMode::Numeric | SortMode::HumanNumeric => {
|
||||||
// find out which range is used for numeric comparisons
|
// 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.
|
/// Get the selection that corresponds to this selector for the line.
|
||||||
/// If needs_fields returned false, tokens may be None.
|
/// If needs_fields returned false, tokens may be None.
|
||||||
fn get_selection<'a>(&self, line: &'a str, tokens: Option<&[Field]>) -> Selection<'a> {
|
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
|
let num_cache = if self.settings.mode == SortMode::Numeric
|
||||||
|| self.settings.mode == SortMode::HumanNumeric
|
|| self.settings.mode == SortMode::HumanNumeric
|
||||||
{
|
{
|
||||||
|
@ -846,7 +846,7 @@ impl FieldSelector {
|
||||||
|
|
||||||
match resolve_index(line, tokens, &self.from) {
|
match resolve_index(line, tokens, &self.from) {
|
||||||
Resolution::StartOfChar(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 {
|
let mut range = match to {
|
||||||
Some(Resolution::StartOfChar(mut 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) {
|
fn output_sorted_lines<'a>(iter: impl Iterator<Item = &'a Line<'a>>, settings: &GlobalSettings) {
|
||||||
if settings.unique {
|
if settings.unique {
|
||||||
print_sorted(
|
print_sorted(
|
||||||
iter.dedup_by(|a, b| compare_by(a, b, &settings) == Ordering::Equal),
|
iter.dedup_by(|a, b| compare_by(a, b, settings) == Ordering::Equal),
|
||||||
&settings,
|
settings,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
print_sorted(iter, &settings);
|
print_sorted(iter, settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1277,16 +1277,16 @@ fn exec(files: &[String], settings: &GlobalSettings) -> i32 {
|
||||||
} else {
|
} else {
|
||||||
let mut lines = files.iter().map(open);
|
let mut lines = files.iter().map(open);
|
||||||
|
|
||||||
ext_sort(&mut lines, &settings);
|
ext_sort(&mut lines, settings);
|
||||||
}
|
}
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sort_by<'a>(unsorted: &mut Vec<Line<'a>>, settings: &GlobalSettings) {
|
fn sort_by<'a>(unsorted: &mut Vec<Line<'a>>, settings: &GlobalSettings) {
|
||||||
if settings.stable || settings.unique {
|
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 {
|
} 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