chore(db): simplify Compact for Vec (#11361)

This commit is contained in:
DaniPopes
2024-10-01 19:44:59 +02:00
committed by GitHub
parent 22ddc98c06
commit b722272c49

View File

@ -150,21 +150,7 @@ where
where where
B: bytes::BufMut + AsMut<[u8]>, B: bytes::BufMut + AsMut<[u8]>,
{ {
encode_varuint(self.len(), buf); self.as_slice().to_compact(buf)
let mut tmp: Vec<u8> = Vec::with_capacity(64);
for element in self {
tmp.clear();
// We don't know the length until we compact it
let length = element.to_compact(&mut tmp);
encode_varuint(length, buf);
buf.put_slice(&tmp);
}
0
} }
#[inline] #[inline]
@ -190,11 +176,7 @@ where
where where
B: bytes::BufMut + AsMut<[u8]>, B: bytes::BufMut + AsMut<[u8]>,
{ {
encode_varuint(self.len(), buf); self.as_slice().specialized_to_compact(buf)
for element in self {
element.to_compact(buf);
}
0
} }
/// To be used by fixed sized types like `Vec<B256>`. /// To be used by fixed sized types like `Vec<B256>`.