Skip to content

Commit

Permalink
Assume same alignment in RawVec
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDiekmann committed Aug 20, 2020
1 parent 303ee3f commit 46b547c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion library/alloc/src/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use core::alloc::LayoutErr;
use core::cmp;
use core::intrinsics;
use core::mem::{self, ManuallyDrop, MaybeUninit};
use core::ops::Drop;
use core::ptr::{NonNull, Unique};
Expand Down Expand Up @@ -495,7 +496,11 @@ where

let memory = if let Some((ptr, old_layout)) = current_memory {
debug_assert_eq!(old_layout.align(), new_layout.align());
unsafe { alloc.grow(ptr, old_layout, new_layout) }
unsafe {
// The allocator checks for alignment equality
intrinsics::assume(old_layout.align() == new_layout.align());
alloc.grow(ptr, old_layout, new_layout)
}
} else {
alloc.alloc(new_layout)
};
Expand Down

0 comments on commit 46b547c

Please sign in to comment.