diff options
author | Neal H. Walfield <neal@pep.foundation> | 2019-10-30 17:00:22 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2019-10-30 17:10:55 +0100 |
commit | 001d04bfc89c3dc9ab06f703ff15cbb1c66f1dc9 (patch) | |
tree | 6db79487ee671d08157d37a488127d33e2965697 /openpgp/src/parse | |
parent | f893274486c61e0a4709e8d36e88c72efdc1446e (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/parse')
-rw-r--r-- | openpgp/src/parse/partial_body.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/openpgp/src/parse/partial_body.rs b/openpgp/src/parse/partial_body.rs index bc4e6309..222e2894 100644 --- a/openpgp/src/parse/partial_body.rs +++ b/openpgp/src/parse/partial_body.rs @@ -4,6 +4,8 @@ use std::io; use std::io::{Error, ErrorKind}; use buffered_reader::{buffered_reader_generic_read_impl, BufferedReader}; + +use crate::vec_truncate; use crate::packet::header::BodyLength; use crate::parse::{Cookie, Hashing}; @@ -203,8 +205,7 @@ impl<T: BufferedReader<Cookie>> BufferedReaderPartialBodyFilter<T> { } } } - - buffer.truncate(amount_buffered); + vec_truncate(&mut buffer, amount_buffered); buffer.shrink_to_fit(); // We're done. |