Remove potentially too costly Packets::default() (#14821)

* Remove potentially too costly Packets::default()

* Fix test...

* Restore Packets::default()

* Restore Packets::default() more
This commit is contained in:
Ryo Onodera
2021-01-29 09:32:38 +09:00
committed by GitHub
parent 8993ac0c74
commit d6873b82ab
5 changed files with 11 additions and 17 deletions

View File

@@ -11,18 +11,11 @@ pub const PACKETS_PER_BATCH: usize = 256;
pub const NUM_RCVMMSGS: usize = 128;
pub const PACKETS_BATCH_SIZE: usize = PACKETS_PER_BATCH * PACKET_DATA_SIZE;
#[derive(Debug, Clone)]
#[derive(Debug, Default, Clone)]
pub struct Packets {
pub packets: PinnedVec<Packet>,
}
//auto derive doesn't support large arrays
impl Default for Packets {
fn default() -> Packets {
Self::with_capacity(NUM_RCVMMSGS)
}
}
pub type PacketsRecycler = Recycler<PinnedVec<Packet>>;
impl Packets {
@@ -75,6 +68,7 @@ pub fn to_packets_chunked<T: Serialize>(xs: &[T], chunks: usize) -> Vec<Packets>
out
}
#[cfg(test)]
pub fn to_packets<T: Serialize>(xs: &[T]) -> Vec<Packets> {
to_packets_chunked(xs, NUM_PACKETS)
}