diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-01-22 12:39:17 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-01-22 12:39:17 +0100 |
commit | 637e10495a0d5f7e980c613aba575de1f3bc0760 (patch) | |
tree | 7dd1f05ac23baea69875162fd8aa0f3b52c47473 | |
parent | e424dca53ebbe10cc0f7ffc7bb959442d57730fe (diff) |
openpgp: Improve performance of test.
-rw-r--r-- | openpgp/src/parse/stream.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs index 79b4c7e8..7ed6badc 100644 --- a/openpgp/src/parse/stream.rs +++ b/openpgp/src/parse/stream.rs @@ -2078,6 +2078,9 @@ mod test { // This test is relatively long running in debug mode. Split it // up. fn detached_verifier_read_size(l: usize) { + lazy_static! { + static ref ZEROS: Vec<u8> = vec![0; 100 * 1024 * 1024]; + } struct Test<'a> { sig: &'a [u8], content: &'a [u8], @@ -2093,7 +2096,7 @@ mod test { Test { sig: crate::tests::message( "emmelie-dorothea-dina-samantha-awina-detached-signature-of-100MB-of-zeros.sig"), - content: &vec![ 0; 100 * 1024 * 1024 ][..], + content: &ZEROS[..], reference: crate::types::Timestamp::try_from(1572602018).unwrap().into(), }, @@ -2105,9 +2108,6 @@ mod test { .map(|f| Cert::from_bytes(crate::tests::key(f)).unwrap()) .collect::<Vec<_>>(); - let mut buffer = Vec::with_capacity(104 * 1024 * 1024); - buffer.resize(buffer.capacity(), 0); - let read_to_end = |v: &mut Verifier<_>, l, buffer: &mut Vec<_>| { let mut offset = 0; loop { @@ -2130,6 +2130,7 @@ mod test { offset }; + let mut buffer = vec![0; 104 * 1024 * 1024]; for test in tests.iter() { let sig = test.sig; let content = test.content; @@ -2162,6 +2163,7 @@ mod test { assert_eq!(got.len(), content.len()); assert_eq!(got, &content[..]); } + crate::vec_truncate(&mut buffer, 0); } #[test] |