mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Move memory location of doubleword storage values
This commit is contained in:
parent
24bc0f6083
commit
95734c10c4
1 changed files with 8 additions and 13 deletions
|
@ -80,17 +80,9 @@ impl<T> RocList<T> {
|
|||
}
|
||||
|
||||
fn get_storage_ptr(&self) -> *const usize {
|
||||
let elem_alignment = core::mem::align_of::<T>();
|
||||
let ptr = self.elements as *const usize;
|
||||
|
||||
unsafe {
|
||||
if elem_alignment <= core::mem::align_of::<usize>() {
|
||||
let ptr = self.elements as *const usize;
|
||||
ptr.offset(-1)
|
||||
} else {
|
||||
let ptr = self.elements as *const (usize, usize);
|
||||
(ptr.offset(-1)) as *const usize
|
||||
}
|
||||
}
|
||||
unsafe { ptr.offset(-1) }
|
||||
}
|
||||
|
||||
fn get_storage_ptr_mut(&mut self) -> *mut usize {
|
||||
|
@ -99,14 +91,17 @@ impl<T> RocList<T> {
|
|||
|
||||
fn get_element_ptr<Q>(elements: *const Q) -> *const usize {
|
||||
let elem_alignment = core::mem::align_of::<T>();
|
||||
let ptr = elements as *const usize;
|
||||
|
||||
unsafe {
|
||||
if elem_alignment <= core::mem::align_of::<usize>() {
|
||||
let ptr = elements as *const usize;
|
||||
ptr.offset(1)
|
||||
} else {
|
||||
let ptr = elements as *const (usize, usize);
|
||||
(ptr.offset(1)) as *const usize
|
||||
// If elements have an alignment bigger than usize (e.g. an i128),
|
||||
// we will have necessarily allocated two usize slots worth of
|
||||
// space for the storage value (with the first usize slot being
|
||||
// padding for alignment's sake), and we need to skip past both.
|
||||
ptr.offset(2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue