mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 13:07:46 +00:00
Cleanup loop, run rustfmt
This commit is contained in:
parent
deb94cef7a
commit
8072e2092a
2 changed files with 16 additions and 11 deletions
|
@ -75,7 +75,7 @@ impl ExternalSorter {
|
||||||
self.parallel = true;
|
self.parallel = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sorts a given iterator with a comparator function, returning a new iterator with items
|
/// Sorts a given iterator with a comparator function, returning a new iterator with items
|
||||||
pub fn sort_by<T, I, F>(&self, iterator: I, cmp: F) -> Result<SortedIterator<T, F>, Error>
|
pub fn sort_by<T, I, F>(&self, iterator: I, cmp: F) -> Result<SortedIterator<T, F>, Error>
|
||||||
where
|
where
|
||||||
|
|
|
@ -18,14 +18,14 @@ extern crate uucore;
|
||||||
mod ext_sorter;
|
mod ext_sorter;
|
||||||
mod numeric_str_cmp;
|
mod numeric_str_cmp;
|
||||||
|
|
||||||
use rayon::prelude::*;
|
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
|
use ext_sorter::{ExternalSorter, Sortable};
|
||||||
use fnv::FnvHasher;
|
use fnv::FnvHasher;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use numeric_str_cmp::{numeric_str_cmp, NumInfo, NumInfoParseSettings};
|
use numeric_str_cmp::{numeric_str_cmp, NumInfo, NumInfoParseSettings};
|
||||||
use ext_sorter::{ExternalSorter, Sortable};
|
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
|
use rayon::prelude::*;
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
@ -271,16 +271,21 @@ impl Sortable for Line {
|
||||||
let result = {
|
let result = {
|
||||||
let mut line_joined = String::new();
|
let mut line_joined = String::new();
|
||||||
let mut selections_joined = SmallVec::new();
|
let mut selections_joined = SmallVec::new();
|
||||||
let p_iter = buf_reader.lines().peekable();
|
let mut p_iter = buf_reader.lines().peekable();
|
||||||
for line in p_iter {
|
while let Some(line) = p_iter.next() {
|
||||||
let mut deserialized_line: Line = serde_json::from_str(&line.unwrap()).unwrap();
|
let mut deserialized_line: Line =
|
||||||
line_joined = format!("{}\n{}\n", line_joined, deserialized_line.line);
|
serde_json::from_str(&line.as_ref().unwrap()).unwrap();
|
||||||
|
if let Some(_next_line) = p_iter.peek() {
|
||||||
|
line_joined = format!("{}\n{}\n", line_joined, deserialized_line.line)
|
||||||
|
} else {
|
||||||
|
line_joined = format!("{}\n{}", line_joined, deserialized_line.line)
|
||||||
|
}
|
||||||
// I think we've done our sorting already and these selctions are irrelevant?
|
// I think we've done our sorting already and these selctions are irrelevant?
|
||||||
// @miDeb what's your sense? Could we just return an empty vec?
|
// @miDeb what's your sense? Could we just return an empty vec?
|
||||||
selections_joined.append(&mut deserialized_line.selections);
|
selections_joined.append(&mut deserialized_line.selections);
|
||||||
}
|
}
|
||||||
Some(Line {
|
Some(Line {
|
||||||
line: line_joined.strip_suffix("\n").unwrap_or("").to_owned(),
|
line: line_joined,
|
||||||
selections: selections_joined,
|
selections: selections_joined,
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
@ -888,7 +893,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
.map(String::from)
|
.map(String::from)
|
||||||
.unwrap_or(format!("{}", DEFAULT_BUF_SIZE));
|
.unwrap_or(format!("{}", DEFAULT_BUF_SIZE));
|
||||||
|
|
||||||
human_numeric_convert(&input)
|
human_numeric_convert(&input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1030,14 +1035,14 @@ fn exec(files: Vec<String>, settings: &GlobalSettings) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only use ext_sorter when we need to.
|
// Only use ext_sorter when we need to.
|
||||||
// Probably faster that we don't create
|
// Probably faster that we don't create
|
||||||
// an owned value each run
|
// an owned value each run
|
||||||
if settings.buffer_size != DEFAULT_BUF_SIZE {
|
if settings.buffer_size != DEFAULT_BUF_SIZE {
|
||||||
lines = ext_sort_by(lines, &settings);
|
lines = ext_sort_by(lines, &settings);
|
||||||
} else {
|
} else {
|
||||||
sort_by(&mut lines, &settings);
|
sort_by(&mut lines, &settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
if settings.merge {
|
if settings.merge {
|
||||||
if settings.unique {
|
if settings.unique {
|
||||||
print_sorted(file_merger.dedup(), &settings)
|
print_sorted(file_merger.dedup(), &settings)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue