Merge pull request #233 from JohnTitor/alloc-removal

Follow-up for rust-lang/rust#74850
pull/235/head
Mark Rousskov 4 years ago committed by GitHub
commit 685ca706a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,12 +10,10 @@ use std::mem;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::marker::PhantomData; use std::marker::PhantomData;
use std::alloc::{ use std::alloc::{
AllocInit,
AllocRef, AllocRef,
Global, Global,
GlobalAlloc, GlobalAlloc,
Layout, Layout,
ReallocPlacement,
handle_alloc_error handle_alloc_error
}; };
@ -42,16 +40,14 @@ impl<T> RawVec<T> {
assert!(elem_size != 0, "capacity overflow"); assert!(elem_size != 0, "capacity overflow");
let (new_cap, ptr) = if self.cap == 0 { let (new_cap, ptr) = if self.cap == 0 {
let ptr = Global.alloc(Layout::array::<T>(1).unwrap(), AllocInit::Uninitialized); let ptr = Global.alloc(Layout::array::<T>(1).unwrap());
(1, ptr) (1, ptr)
} else { } else {
let new_cap = 2 * self.cap; let new_cap = 2 * self.cap;
let c: NonNull<T> = self.ptr.into(); let c: NonNull<T> = self.ptr.into();
let ptr = Global.grow(c.cast(), let ptr = Global.grow(c.cast(),
Layout::array::<T>(self.cap).unwrap(), Layout::array::<T>(self.cap).unwrap(),
Layout::array::<T>(new_cap).unwrap().size(), Layout::array::<T>(new_cap).unwrap().size());
ReallocPlacement::MayMove,
AllocInit::Uninitialized);
(new_cap, ptr) (new_cap, ptr)
}; };

Loading…
Cancel
Save