Improve the RoaringBitmap codec to reserve enough vector space

This commit is contained in:
Clément Renault 2020-08-29 11:21:30 +02:00
parent 3fe497e129
commit 816db7a0aa
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -15,7 +15,7 @@ impl heed::BytesEncode<'_> for RoaringBitmapCodec {
type EItem = RoaringBitmap; type EItem = RoaringBitmap;
fn bytes_encode(item: &Self::EItem) -> Option<Cow<[u8]>> { fn bytes_encode(item: &Self::EItem) -> Option<Cow<[u8]>> {
let mut bytes = Vec::new(); let mut bytes = Vec::with_capacity(item.serialized_size());
item.serialize_into(&mut bytes).ok()?; item.serialize_into(&mut bytes).ok()?;
Some(Cow::Owned(bytes)) Some(Cow::Owned(bytes))
} }