remove undesired drop

This commit is contained in:
Folkert 2022-06-11 20:08:06 +02:00
parent 6bf74629e2
commit dcdffcc489
No known key found for this signature in database
GPG Key ID: 1F17F6FFD112B97C
2 changed files with 16 additions and 8 deletions

View File

@ -154,7 +154,6 @@ where
if storage.get().is_unique() {
unsafe {
let old_alloc = self.ptr_to_allocation();
old_elements_ptr = elements.as_ptr();
// Try to reallocate in-place.
let new_alloc = roc_realloc(
@ -187,6 +186,11 @@ where
new_elems = Self::elems_with_capacity(new_len);
old_elements_ptr = elements.as_ptr();
unsafe {
// Copy the old elements to the new allocation.
copy_nonoverlapping(old_elements_ptr, new_elems.as_ptr(), self.length);
}
// Decrease the current allocation's reference count.
let mut new_storage = storage.get();
let needs_dealloc = new_storage.decrease();
@ -212,16 +216,17 @@ where
}
}
unsafe {
// Copy the old elements to the new allocation.
copy_nonoverlapping(old_elements_ptr, new_elems.as_ptr(), self.length);
}
let length = self.length;
*self = Self {
let mut updated = Self {
elements: Some(new_elems),
length: self.length,
length,
capacity: new_len,
};
std::mem::swap(self, &mut updated);
std::mem::forget(updated);
}
pub fn from_slice(slice: &[T]) -> Self {

View File

@ -152,9 +152,12 @@ impl RocStr {
roc_list.reserve(bytes);
*self = RocStr(RocStrInner {
let mut updated = RocStr(RocStrInner {
heap_allocated: ManuallyDrop::new(roc_list),
});
std::mem::swap(self, &mut updated);
std::mem::forget(updated);
}
}