use unstable sort

This commit is contained in:
Lynne Megido 2021-08-25 15:26:41 +10:00
parent 4192d37854
commit a2ce336fe7
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90

View file

@ -136,12 +136,12 @@ pub trait FormatSteps {
// sort errors so unreadable files appear before files with unknown mimetypes - ScanError impls Ord such that
// ScanError::File > ScanError::Mime
let errors = entries.iter().filter_map(|e| e.as_ref().err()).sorted();
let errors = entries.iter().filter_map(|e| e.as_ref().err()).sorted_unstable();
// sort files so that files with no known extension come before those with known extensions - None > Some("jpg")
let findings = entries
.iter()
.filter_map(|e| e.as_ref().ok())
.sorted_by(|a, b| b.recommended_extension().cmp(&a.recommended_extension()).reverse());
.sorted_unstable_by(|a, b| b.recommended_extension().cmp(&a.recommended_extension()).reverse());
for error in errors {
match error {
@ -343,8 +343,16 @@ impl Format for Json {
let result = serde_json::to_writer_pretty(
f,
&SerdeEntries {
errors: &entries.iter().filter_map(|e| e.as_ref().err()).sorted().collect(),
findings: &entries.iter().filter_map(|f| f.as_ref().ok()).sorted().collect(),
errors: &entries
.iter()
.filter_map(|e| e.as_ref().err())
.sorted_unstable()
.collect(),
findings: &entries
.iter()
.filter_map(|f| f.as_ref().ok())
.sorted_unstable()
.collect(),
},
);