Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Nov 24, 2023
1 parent 08980f4 commit aa49350
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,17 +535,12 @@ impl<T> RcSliceBuilder<T> {

// Normalize the allocation size to a power of 2 or the halfway point
// between to powers of 2.
let leading_zeros = size.leading_zeros();
let pow2 = (1usize << (usize::BITS - 1)) >> leading_zeros;
let size = if size == pow2 {
size
let next_pow2 = size.next_power_of_two();
let size = if next_pow2 <= 2048 {
next_pow2
} else {
let halfway = (3usize << (usize::BITS - 2)) >> leading_zeros;
if size > halfway {
pow2 << 1
} else {
halfway
}
let gap = next_pow2 / 16 - 1;
(size + gap) & !gap
};
(Layout::from_size_align(size, align).unwrap(), offset)
}
Expand Down

0 comments on commit aa49350

Please sign in to comment.