mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
sort: compare strings before comparing hashes
Since lines that compare equal should be sorted together, we need to first compare the lines (taking settings into account). Only if they do not compare equal we should compare the hashes.
This commit is contained in:
+16
-1
@@ -1398,7 +1398,22 @@ fn compare_by<'a>(
|
||||
let settings = &selector.settings;
|
||||
|
||||
let cmp: Ordering = match settings.mode {
|
||||
SortMode::Random => random_shuffle(a_str, b_str, &global_settings.salt.unwrap()),
|
||||
SortMode::Random => {
|
||||
// check if the two strings are equal
|
||||
if custom_str_cmp(
|
||||
a_str,
|
||||
b_str,
|
||||
settings.ignore_non_printing,
|
||||
settings.dictionary_order,
|
||||
settings.ignore_case,
|
||||
) == Ordering::Equal
|
||||
{
|
||||
Ordering::Equal
|
||||
} else {
|
||||
// Only if they are not equal compare by the hash
|
||||
random_shuffle(a_str, b_str, &global_settings.salt.unwrap())
|
||||
}
|
||||
}
|
||||
SortMode::Numeric => {
|
||||
let a_num_info = &a_line_data.num_infos
|
||||
[a.index * global_settings.precomputed.num_infos_per_line + num_info_index];
|
||||
|
||||
@@ -235,6 +235,16 @@ fn test_random_shuffle_two_runs_not_the_same() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_random_ignore_case() {
|
||||
let input = "ABC\nABc\nAbC\nAbc\naBC\naBc\nabC\nabc\n";
|
||||
new_ucmd!()
|
||||
.args(&["-fR"])
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_is(input);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_floats_and_ints() {
|
||||
test_helper(
|
||||
|
||||
Reference in New Issue
Block a user