refactor: Use `Vec::clear` instead of `Vec::truncate(0)`

pull/24376/head
Carol (Nichols || Goulding) 2020-06-19 15:23:15 -04:00
parent 1e341a7321
commit 683205ad03
5 changed files with 5 additions and 5 deletions

View File

@ -75,7 +75,7 @@ fn benchmark_decode<T>(
|b, &decoded_len| {
let mut decoded_mut = Vec::with_capacity(decoded_len);
b.iter(|| {
decoded_mut.truncate(0);
decoded_mut.clear();
decode(&encoded, &mut decoded_mut).unwrap();
});
},

View File

@ -21,7 +21,7 @@ fn is_sentinel_u64(v: u64, sentinel: u64) -> bool {
/// representations based on those are stored.
#[allow(clippy::many_single_char_names)]
pub fn encode(src: &[f64], dst: &mut Vec<u8>) -> Result<(), Box<dyn Error>> {
dst.truncate(0); // reset buffer.
dst.clear(); // reset buffer.
if src.is_empty() {
return Ok(());
}

View File

@ -16,7 +16,7 @@ enum Encoding {
/// further compressed if possible, either via bit-packing using simple8b or by
/// run-length encoding the deltas if they're all the same.
pub fn encode(src: &[i64], dst: &mut Vec<u8>) -> Result<(), Box<dyn Error>> {
dst.truncate(0); // reset buffer.
dst.clear(); // reset buffer.
if src.is_empty() {
return Ok(());
}

View File

@ -12,7 +12,7 @@ const MAX_I32: usize = i32::MAX as usize;
/// Encodes a slice of byte slices representing string data into a vector of bytes. Currently uses
/// Snappy compression.
pub fn encode(src: &[&[u8]], dst: &mut Vec<u8>) -> Result<(), Box<dyn Error>> {
dst.truncate(0); // reset buffer
dst.clear(); // reset buffer
if src.is_empty() {
return Ok(());
}

View File

@ -17,7 +17,7 @@ enum Encoding {
/// encoded using RLE. If not, as long as the deltas are not bigger than simple8b::MAX_VALUE
/// they can be encoded using simple8b.
pub fn encode(src: &[i64], dst: &mut Vec<u8>) -> Result<(), Box<dyn Error>> {
dst.truncate(0); // reset buffer.
dst.clear(); // reset buffer.
if src.is_empty() {
return Ok(());
}