diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-11-18 14:35:04 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-11-18 14:54:09 +0100 |
commit | a5fade1d635d75e474294a06870251d8f617db08 (patch) | |
tree | 0a76e0d552f37ed764601d933981e6d18823e338 /openpgp | |
parent | 35b63042464796574f91c6f0c909059acc45904d (diff) |
openpgp: Optimize .clear() for byte vectors.
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/src/armor.rs | 10 | ||||
-rw-r--r-- | openpgp/src/crypto/aead.rs | 4 | ||||
-rw-r--r-- | openpgp/src/crypto/symmetric.rs | 4 | ||||
-rw-r--r-- | openpgp/src/serialize/partial_body.rs | 2 |
4 files changed, 10 insertions, 10 deletions
diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs index dfdf0c2f..86c22f2a 100644 --- a/openpgp/src/armor.rs +++ b/openpgp/src/armor.rs @@ -217,7 +217,7 @@ impl<W: Write> Writer<W> { self.sink.as_mut().ok_or_else(Self::e_finalized)? .write_all(&self.header)?; // Release memory. - self.header.clear(); + crate::vec_truncate(&mut self.header, 0); self.header.shrink_to_fit(); } Ok(()) @@ -337,7 +337,7 @@ impl<W: Write> Write for Writer<W> { &self.stash, base64::STANDARD_NO_PAD).as_bytes())?; self.column += 4; self.linebreak()?; - self.stash.clear(); + crate::vec_truncate(&mut self.stash, 0); } // Ensure that a multiple of 3 bytes are encoded, stash the @@ -637,7 +637,7 @@ impl<'a> Reader<'a> { if lines > 0 { // Find the start of the next line. self.source.drop_through(&[b'\n'], true)?; - prefix.clear(); + crate::vec_truncate(&mut prefix, 0); } lines += 1; @@ -653,7 +653,7 @@ impl<'a> Reader<'a> { let c = self.source.data(1)?[0]; if c == b'\n' { // We found a newline while walking whitespace, reset prefix - prefix.clear(); + crate::vec_truncate(&mut prefix, 0); } else { prefix.push(self.source.data_hard(1)?[0]); } @@ -742,7 +742,7 @@ impl<'a> Reader<'a> { // was purely whitespace. Any non-whitespace remains an error // while searching for the armor header if it's not repeated. if prefix.iter().all(|b| (*b as char).is_ascii_whitespace()) { - prefix.clear(); + crate::vec_truncate(&mut prefix, 0); } else { // Nope, we have actually failed to read this properly return Err( diff --git a/openpgp/src/crypto/aead.rs b/openpgp/src/crypto/aead.rs index ffb99ba0..72d029a4 100644 --- a/openpgp/src/crypto/aead.rs +++ b/openpgp/src/crypto/aead.rs @@ -645,7 +645,7 @@ impl<W: io::Write> Encryptor<W> { aead.encrypt(&mut self.scratch, &self.buffer); self.bytes_encrypted += self.scratch.len() as u64; self.chunk_index += 1; - self.buffer.clear(); + crate::vec_truncate(&mut self.buffer, 0); inner.write_all(&self.scratch)?; // Write digest. @@ -694,7 +694,7 @@ impl<W: io::Write> Encryptor<W> { aead.encrypt(&mut self.scratch, &self.buffer); self.bytes_encrypted += self.scratch.len() as u64; self.chunk_index += 1; - self.buffer.clear(); + crate::vec_truncate(&mut self.buffer, 0); inner.write_all(&self.scratch)?; // Write digest. diff --git a/openpgp/src/crypto/symmetric.rs b/openpgp/src/crypto/symmetric.rs index 0d0dfbde..b6aa799b 100644 --- a/openpgp/src/crypto/symmetric.rs +++ b/openpgp/src/crypto/symmetric.rs @@ -433,7 +433,7 @@ impl<W: io::Write> Encryptor<W> { if self.buffer.len() > 0 { unsafe { self.scratch.set_len(self.buffer.len()) } self.cipher.encrypt(&mut self.iv, &mut self.scratch, &self.buffer)?; - self.buffer.clear(); + crate::vec_truncate(&mut self.buffer, 0); inner.write_all(&self.scratch)?; } Ok(inner) @@ -476,7 +476,7 @@ impl<W: io::Write> io::Write for Encryptor<W> { self.cipher.encrypt(&mut self.iv, &mut self.scratch, &self.buffer) .map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, format!("{}", e)))?; - self.buffer.clear(); + crate::vec_truncate(&mut self.buffer, 0); inner.write_all(&self.scratch)?; } } diff --git a/openpgp/src/serialize/partial_body.rs b/openpgp/src/serialize/partial_body.rs index 9a44a562..26bb0e14 100644 --- a/openpgp/src/serialize/partial_body.rs +++ b/openpgp/src/serialize/partial_body.rs @@ -114,7 +114,7 @@ impl<'a, C: 'a> PartialBodyFilter<'a, C> { // Write the body. inner.write_all(&self.buffer[..])?; - self.buffer.clear(); + crate::vec_truncate(&mut self.buffer, 0); inner.write_all(other)?; } else { while self.buffer.len() + other.len() > self.buffer_threshold { |