summaryrefslogtreecommitdiffstats
path: root/openpgp/src/armor.rs
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2019-10-30 17:00:22 +0100
committerNeal H. Walfield <neal@pep.foundation>2019-10-30 17:10:55 +0100
commit001d04bfc89c3dc9ab06f703ff15cbb1c66f1dc9 (patch)
tree6db79487ee671d08157d37a488127d33e2965697 /openpgp/src/armor.rs
parentf893274486c61e0a4709e8d36e88c72efdc1446e (diff)
openpgp,buffered-reader: Optimize Vec<u8>::truncate manually
- On debug builds, Vec<u8>::truncate is very, very slow. For instance, running the decrypt_test_stream test takes 51 seconds on my (Neal's) computer using Vec<u8>::truncate and <0.1 seconds using `unsafe { v.set_len(len); }`. The issue is that the compiler calls drop on every element that is dropped, even though a u8 doesn't have a drop implementation. The compiler optimizes this away at high optimization levels, but those levels make debugging harder.
Diffstat (limited to 'openpgp/src/armor.rs')
-rw-r--r--openpgp/src/armor.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs
index 85a0a967..c593fdee 100644
--- a/openpgp/src/armor.rs
+++ b/openpgp/src/armor.rs
@@ -35,6 +35,7 @@ use std::str;
use std::borrow::Cow;
use quickcheck::{Arbitrary, Gen};
+use crate::vec_truncate;
use crate::packet::prelude::*;
use crate::packet::header::BodyLength;
use crate::packet::header::ctb::{CTBNew, CTBOld};
@@ -931,7 +932,7 @@ fn base64_filter(mut bytes: Cow<[u8]>, base64_data_max: usize,
(Cow::Borrowed(&s[..base64_len]), unfiltered_complete_len,
prefix_remaining),
Cow::Owned(mut v) => {
- v.truncate(base64_len);
+ vec_truncate(&mut v, base64_len);
(Cow::Owned(v), unfiltered_complete_len, prefix_remaining)
}
}