io: use Vec::with_capacity

This commit is contained in:
Johannes Altmanninger 2023-10-13 10:59:12 +02:00
parent c6e905a1b9
commit b8c5627eb1

View File

@ -82,7 +82,7 @@ impl SeparatedBuffer {
}
/// \return the contents size.
pub fn size(&self) -> usize {
pub fn len(&self) -> usize {
self.contents_size
}
@ -94,8 +94,7 @@ impl SeparatedBuffer {
/// Serialize the contents to a single string, where explicitly separated elements have a
/// newline appended.
pub fn newline_serialized(&self) -> Vec<u8> {
let mut result = vec![];
result.reserve(self.size());
let mut result = Vec::with_capacity(self.len());
for elem in &self.elements {
result.extend_from_slice(&elem.contents);
if elem.is_explicitly_separated() {