Skip to content

Commit

Permalink
Add method Vec<T>::as_mut_ptr()
Browse files Browse the repository at this point in the history
  • Loading branch information
cadencemarseille committed Mar 16, 2014
1 parent 7156ded commit 5db7f7e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/libstd/vec_ng.rs
Expand Up @@ -415,8 +415,7 @@ impl<T> Vec<T> {
unsafe { // infallible
// The spot to put the new value
{
let slice = self.as_mut_slice();
let p = slice.as_mut_ptr().offset(index as int);
let p = self.as_mut_ptr().offset(index as int);
// Shift everything over to make space. (Duplicating the
// `index`th element into two consecutive places.)
ptr::copy_memory(p.offset(1), &*p, len - index);
Expand All @@ -434,9 +433,8 @@ impl<T> Vec<T> {
unsafe { // infallible
let ret;
{
let slice = self.as_mut_slice();
// the place we are taking from.
let ptr = slice.as_mut_ptr().offset(index as int);
let ptr = self.as_mut_ptr().offset(index as int);
// copy it out, unsafely having a copy of the value on
// the stack and in the vector at the same time.
ret = Some(ptr::read(ptr as *T));
Expand Down Expand Up @@ -499,6 +497,11 @@ impl<T> Vec<T> {
pub fn as_ptr(&self) -> *T {
self.as_slice().as_ptr()
}

#[inline]
pub fn as_mut_ptr(&mut self) -> *mut T {
self.as_mut_slice().as_mut_ptr()
}
}

impl<T> Mutable for Vec<T> {
Expand Down

5 comments on commit 5db7f7e

@bors
Copy link
Contributor

@bors bors commented on 5db7f7e Mar 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at cadencemarseille@5db7f7e

@bors
Copy link
Contributor

@bors bors commented on 5db7f7e Mar 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging cadencemarseille/rust/vec_ng-as_mut_ptr = 5db7f7e into auto

@bors
Copy link
Contributor

@bors bors commented on 5db7f7e Mar 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cadencemarseille/rust/vec_ng-as_mut_ptr = 5db7f7e merged ok, testing candidate = b6d5b8f

@bors
Copy link
Contributor

@bors bors commented on 5db7f7e Mar 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = b6d5b8f

Please sign in to comment.