core: Optimize read_record()

The serial type varints are typically just a single byte, so let's
allocate at least header size bytes in the vector to reduce need to grow
it.
This commit is contained in:
Pekka Enberg
2024-01-24 17:56:09 +02:00
parent 4804c2a686
commit 274c8109d6

View File

@@ -301,7 +301,7 @@ pub fn read_record(payload: &[u8]) -> Result<Record> {
assert!((header_size as usize) >= nr);
let mut header_size = (header_size as usize) - nr;
pos += nr;
let mut serial_types = Vec::new();
let mut serial_types = Vec::with_capacity(header_size);
while header_size > 0 {
let (serial_type, nr) = read_varint(&payload[pos..])?;
let serial_type = SerialType::try_from(serial_type)?;