Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
bucket_map: Length must be 1 if including header in get_slice() (#31445)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored May 3, 2023
1 parent a9515e9 commit 9a4618a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions bucket_map/src/bucket_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ impl<O: BucketOccupied> Drop for BucketStorage<O> {
}
}

#[allow(dead_code)]
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub(crate) enum IncludeHeader {
/// caller wants header
/// caller wants header included
Header,
/// caller wants header skipped
NoHeader,
Expand Down Expand Up @@ -290,6 +290,10 @@ impl<O: BucketOccupied> BucketStorage<O> {
}

pub(crate) fn get_slice<T>(&self, ix: u64, len: u64, header: IncludeHeader) -> &[T] {
// If the caller is including the header, then `len` *must* be 1
debug_assert!(
(header == IncludeHeader::NoHeader) || (header == IncludeHeader::Header && len == 1)
);
let start = self.get_start_offset(ix, header);
let slice = {
let size = std::mem::size_of::<T>() * len as usize;
Expand All @@ -311,6 +315,10 @@ impl<O: BucketOccupied> BucketStorage<O> {
len: u64,
header: IncludeHeader,
) -> &mut [T] {
// If the caller is including the header, then `len` *must* be 1
debug_assert!(
(header == IncludeHeader::NoHeader) || (header == IncludeHeader::Header && len == 1)
);
let start = self.get_start_offset(ix, header);
let slice = {
let size = std::mem::size_of::<T>() * len as usize;
Expand Down

0 comments on commit 9a4618a

Please sign in to comment.