summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-09-27 15:40:03 +0300
committerLars Wirzenius <liw@sequoia-pgp.org>2021-09-30 08:31:11 +0300
commitfe78f2fc0baa68aa2b9c0125c1b89dc23121d68b (patch)
tree277560e3f5285f065f27256d7b986aa386e57618
parentf098a0a37df4cddd98899e4e94def4380a0f1d15 (diff)
Use .sort_unstable for speed
A stable sort is one where values that compare equal are in the same order relative to each other in the output as they were in the input. Thus, if input has values a0, b, and a1, with a0==a1, a0<b, a1<b, then the output of a stable sort is guaranteed to be be [a0, a1, b]. For an unstable sort, the output may also be [a1, a0, b]. This can matter if, for example, the values are structs and only one field is used for comparison. On data where an unstable sort (.sort_unstable) works, it's bad to use a stable sort (.sort), because it uses more CPU without affecting the end result. If the types of values in a vector are primitive types, as they are in the cases changed by this commit, an unstable sort will do just fine. Found by clippy lint stable_sort_primitive: https://rust-lang.github.io/rust-clippy/master/index.html#stable_sort_primitive
-rw-r--r--openpgp/src/armor.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs
index cdb6b361..d009dacc 100644
--- a/openpgp/src/armor.rs
+++ b/openpgp/src/armor.rs
@@ -840,7 +840,7 @@ impl<'a> Reader<'a> {
// If there are no dashes at all, match on the BEGIN.
valid_start.push(b'B');
- valid_start.sort();
+ valid_start.sort_unstable();
valid_start.dedup();
valid_start
};
@@ -858,7 +858,7 @@ impl<'a> Reader<'a> {
// If there are no dashes at all, match on the BEGIN.
valid_start.push(b'B');
- valid_start.sort();
+ valid_start.sort_unstable();
valid_start.dedup();
valid_start
};