Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(db): simplify Compact for Vec #11361

Merged
merged 1 commit into from
Oct 1, 2024
Merged

Conversation

DaniPopes
Copy link
Member

Reuse slice impl since it's the same

@DaniPopes DaniPopes requested a review from joshieDo as a code owner October 1, 2024 01:39
@DaniPopes DaniPopes enabled auto-merge October 1, 2024 01:39
@DaniPopes DaniPopes requested a review from mattsse October 1, 2024 01:39
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, indeed

/// Returns 0 since we won't include it in the `StructFlags`.
#[inline]
fn to_compact<B>(&self, buf: &mut B) -> usize
where
B: bytes::BufMut + AsMut<[u8]>,
{
encode_varuint(self.len(), 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
}

@DaniPopes DaniPopes added this pull request to the merge queue Oct 1, 2024
@mattsse mattsse added C-debt A clean up/refactor of existing code A-db Related to the database labels Oct 1, 2024
Merged via the queue into main with commit b722272 Oct 1, 2024
36 checks passed
@DaniPopes DaniPopes deleted the dani/simple-vec-compact branch October 1, 2024 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-db Related to the database C-debt A clean up/refactor of existing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants