Skip to content

Commit fec6716

Browse files
committed
std: Remove push_fast from OwnedVector. Closes #8769
This is an unsafe implementation detail of `push`.
1 parent d1dde99 commit fec6716

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

src/libstd/vec.rs

+21-22
Original file line numberDiff line numberDiff line change
@@ -1201,8 +1201,6 @@ pub trait OwnedVector<T> {
12011201
fn shrink_to_fit(&mut self);
12021202

12031203
fn push(&mut self, t: T);
1204-
unsafe fn push_fast(&mut self, t: T);
1205-
12061204
fn push_all_move(&mut self, rhs: ~[T]);
12071205
fn pop(&mut self) -> T;
12081206
fn pop_opt(&mut self) -> Option<T>;
@@ -1334,7 +1332,7 @@ impl<T> OwnedVector<T> for ~[T] {
13341332
self.reserve_at_least(new_len);
13351333
}
13361334

1337-
self.push_fast(t);
1335+
push_fast(self, t);
13381336
} else {
13391337
let repr: **Vec<()> = cast::transmute(&mut *self);
13401338
let fill = (**repr).fill;
@@ -1343,29 +1341,30 @@ impl<T> OwnedVector<T> for ~[T] {
13431341
self.reserve_at_least(new_len);
13441342
}
13451343

1346-
self.push_fast(t);
1344+
push_fast(self, t);
13471345
}
13481346
}
1349-
}
13501347

1351-
// This doesn't bother to make sure we have space.
1352-
#[inline] // really pretty please
1353-
unsafe fn push_fast(&mut self, t: T) {
1354-
if contains_managed::<T>() {
1355-
let repr: **mut Box<Vec<u8>> = cast::transmute(self);
1356-
let fill = (**repr).data.fill;
1357-
(**repr).data.fill += sys::nonzero_size_of::<T>();
1358-
let p = to_unsafe_ptr(&((**repr).data.data));
1359-
let p = ptr::offset(p, fill as int) as *mut T;
1360-
intrinsics::move_val_init(&mut(*p), t);
1361-
} else {
1362-
let repr: **mut Vec<u8> = cast::transmute(self);
1363-
let fill = (**repr).fill;
1364-
(**repr).fill += sys::nonzero_size_of::<T>();
1365-
let p = to_unsafe_ptr(&((**repr).data));
1366-
let p = ptr::offset(p, fill as int) as *mut T;
1367-
intrinsics::move_val_init(&mut(*p), t);
1348+
// This doesn't bother to make sure we have space.
1349+
#[inline] // really pretty please
1350+
unsafe fn push_fast<T>(this: &mut ~[T], t: T) {
1351+
if contains_managed::<T>() {
1352+
let repr: **mut Box<Vec<u8>> = cast::transmute(this);
1353+
let fill = (**repr).data.fill;
1354+
(**repr).data.fill += sys::nonzero_size_of::<T>();
1355+
let p = to_unsafe_ptr(&((**repr).data.data));
1356+
let p = ptr::offset(p, fill as int) as *mut T;
1357+
intrinsics::move_val_init(&mut(*p), t);
1358+
} else {
1359+
let repr: **mut Vec<u8> = cast::transmute(this);
1360+
let fill = (**repr).fill;
1361+
(**repr).fill += sys::nonzero_size_of::<T>();
1362+
let p = to_unsafe_ptr(&((**repr).data));
1363+
let p = ptr::offset(p, fill as int) as *mut T;
1364+
intrinsics::move_val_init(&mut(*p), t);
1365+
}
13681366
}
1367+
13691368
}
13701369

13711370
/// Takes ownership of the vector `rhs`, moving all elements into

0 commit comments

Comments
 (0)