From 9c8dd09d60d32d42b5b0d0e4f9806e8c0208267e Mon Sep 17 00:00:00 2001 From: theteachr Date: Sun, 24 Dec 2023 02:11:51 +0530 Subject: [PATCH] Save a call to `reverse` By flipping the comparison operation inside the closure, `.reverse()` can be avoided. --- src/model.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/model.rs b/src/model.rs index 3a213dd..f12270a 100644 --- a/src/model.rs +++ b/src/model.rs @@ -52,8 +52,11 @@ impl Model { result.push((path.clone(), rank)); } } - result.sort_by(|(_, rank1), (_, rank2)| rank1.partial_cmp(rank2).expect(&format!("{rank1} and {rank2} are not comparable"))); - result.reverse(); + result.sort_by(|(_, rank1), (_, rank2)| { + rank2 + .partial_cmp(rank1) + .expect(&format!("{rank1} and {rank2} are comparable")) + }); result }