Skip to content

Commit

Permalink
Merge pull request #233 from JohnTitor/alloc-removal
Browse files Browse the repository at this point in the history
Follow-up for rust-lang/rust#74850
  • Loading branch information
Mark-Simulacrum authored Aug 18, 2020
2 parents bfe1ab9 + be0687a commit 685ca70
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/vec-final.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ use std::mem;
use std::ops::{Deref, DerefMut};
use std::marker::PhantomData;
use std::alloc::{
AllocInit,
AllocRef,
Global,
GlobalAlloc,
Layout,
ReallocPlacement,
handle_alloc_error
};

Expand All @@ -42,16 +40,14 @@ impl<T> RawVec<T> {
assert!(elem_size != 0, "capacity overflow");

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)
} else {
let new_cap = 2 * self.cap;
let c: NonNull<T> = self.ptr.into();
let ptr = Global.grow(c.cast(),
Layout::array::<T>(self.cap).unwrap(),
Layout::array::<T>(new_cap).unwrap().size(),
ReallocPlacement::MayMove,
AllocInit::Uninitialized);
Layout::array::<T>(new_cap).unwrap().size());
(new_cap, ptr)
};

Expand Down

0 comments on commit 685ca70

Please sign in to comment.