Skip to content

Commit b6d5b8f

Browse files
committed
auto merge of #12945 : cadencemarseille/rust/vec_ng-as_mut_ptr, r=alexcrichton
2 parents eb68bee + 5db7f7e commit b6d5b8f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/libstd/vec_ng.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,7 @@ impl<T> Vec<T> {
415415
unsafe { // infallible
416416
// The spot to put the new value
417417
{
418-
let slice = self.as_mut_slice();
419-
let p = slice.as_mut_ptr().offset(index as int);
418+
let p = self.as_mut_ptr().offset(index as int);
420419
// Shift everything over to make space. (Duplicating the
421420
// `index`th element into two consecutive places.)
422421
ptr::copy_memory(p.offset(1), &*p, len - index);
@@ -434,9 +433,8 @@ impl<T> Vec<T> {
434433
unsafe { // infallible
435434
let ret;
436435
{
437-
let slice = self.as_mut_slice();
438436
// the place we are taking from.
439-
let ptr = slice.as_mut_ptr().offset(index as int);
437+
let ptr = self.as_mut_ptr().offset(index as int);
440438
// copy it out, unsafely having a copy of the value on
441439
// the stack and in the vector at the same time.
442440
ret = Some(ptr::read(ptr as *T));
@@ -499,6 +497,11 @@ impl<T> Vec<T> {
499497
pub fn as_ptr(&self) -> *T {
500498
self.as_slice().as_ptr()
501499
}
500+
501+
#[inline]
502+
pub fn as_mut_ptr(&mut self) -> *mut T {
503+
self.as_mut_slice().as_mut_ptr()
504+
}
502505
}
503506

504507
impl<T> Mutable for Vec<T> {

0 commit comments

Comments
 (0)