From 001d04bfc89c3dc9ab06f703ff15cbb1c66f1dc9 Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Wed, 30 Oct 2019 17:00:22 +0100 Subject: openpgp,buffered-reader: Optimize Vec::truncate manually - On debug builds, Vec::truncate is very, very slow. For instance, running the decrypt_test_stream test takes 51 seconds on my (Neal's) computer using Vec::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. --- openpgp/src/parse/partial_body.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'openpgp/src/parse') 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> BufferedReaderPartialBodyFilter { } } } - - buffer.truncate(amount_buffered); + vec_truncate(&mut buffer, amount_buffered); buffer.shrink_to_fit(); // We're done. -- cgit v1.2.3