Skip to content

Commit

Permalink
Update mod.rs
Browse files Browse the repository at this point in the history
- Removed unnecessary code from nightly `calculate_layout`
- Added comment for `Bucket::ptr` data member
  • Loading branch information
iwa0 authored May 22, 2020
1 parent 47c10e7 commit 7027781
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,8 @@ fn bucket_mask_to_capacity(bucket_mask: usize) -> usize {
fn calculate_layout<T>(buckets: usize) -> Option<(Layout, usize)> {
debug_assert!(buckets.is_power_of_two());

let common_align = usize::max(mem::align_of::<T>(), Group::WIDTH);
// Array of buckets
let padded_data = Layout::array::<T>(buckets).ok()?.align_to(common_align).ok()?.pad_to_align();
let data = Layout::array::<T>(buckets).ok()?;

// Array of control bytes. This must be aligned to the group size.
//
Expand All @@ -235,7 +234,7 @@ fn calculate_layout<T>(buckets: usize) -> Option<(Layout, usize)> {
// There must be no padding between two tables.
debug_assert_eq!(padded_data.padding_needed_for(Group::WIDTH), 0);

padded_data.extend(ctrl).ok()
data.extend(ctrl).ok()
}

/// Returns a Layout which describes the allocation required for a hash table,
Expand Down Expand Up @@ -266,6 +265,9 @@ fn calculate_layout<T>(buckets: usize) -> Option<(Layout, usize)> {
/// is a ZST, then we instead track the index of the element in the table so
/// that `erase` works properly.
pub struct Bucket<T> {
// Actually it is pointer to next element than element itself
// this is needed to maintain pointer arithmetic invariants
// keeping direct pointer to element introduces difficulty.
// Using `NonNull` for variance and niche layout
ptr: NonNull<T>,
}
Expand Down

0 comments on commit 7027781

Please sign in to comment.