1
Fork 0

Replace init() with uninit() where appropriate

This commit is contained in:
James Miller 2013-05-09 22:41:26 +12:00
parent 050c744c23
commit f5ab112e6b
4 changed files with 9 additions and 14 deletions

View file

@ -25,7 +25,7 @@ pub mod rusti {
/// Casts the value at `src` to U. The two types must have the same length. /// Casts the value at `src` to U. The two types must have the same length.
pub unsafe fn transmute_copy<T, U>(src: &T) -> U { pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
let mut dest: U = unstable::intrinsics::init(); let mut dest: U = unstable::intrinsics::uninit();
{ {
let dest_ptr: *mut u8 = rusti::transmute(&mut dest); let dest_ptr: *mut u8 = rusti::transmute(&mut dest);
let src_ptr: *u8 = rusti::transmute(src); let src_ptr: *u8 = rusti::transmute(src);

View file

@ -591,8 +591,7 @@ pub fn pop<T>(v: &mut ~[T]) -> T {
} }
let valptr = ptr::to_mut_unsafe_ptr(&mut v[ln - 1u]); let valptr = ptr::to_mut_unsafe_ptr(&mut v[ln - 1u]);
unsafe { unsafe {
// FIXME #4204: Should be uninit() - we don't need this zeroed let mut val = intrinsics::uninit();
let mut val = intrinsics::init();
val <-> *valptr; val <-> *valptr;
raw::set_len(v, ln - 1u); raw::set_len(v, ln - 1u);
val val
@ -666,8 +665,7 @@ pub fn push_all_move<T>(v: &mut ~[T], mut rhs: ~[T]) {
unsafe { unsafe {
do as_mut_buf(rhs) |p, len| { do as_mut_buf(rhs) |p, len| {
for uint::range(0, len) |i| { for uint::range(0, len) |i| {
// FIXME #4204 Should be uninit() - don't need to zero let mut x = intrinsics::uninit();
let mut x = intrinsics::init();
x <-> *ptr::mut_offset(p, i); x <-> *ptr::mut_offset(p, i);
push(&mut *v, x); push(&mut *v, x);
} }
@ -683,8 +681,7 @@ pub fn truncate<T>(v: &mut ~[T], newlen: uint) {
unsafe { unsafe {
// This loop is optimized out for non-drop types. // This loop is optimized out for non-drop types.
for uint::range(newlen, oldlen) |i| { for uint::range(newlen, oldlen) |i| {
// FIXME #4204 Should be uninit() - don't need to zero let mut dropped = intrinsics::uninit();
let mut dropped = intrinsics::init();
dropped <-> *ptr::mut_offset(p, i); dropped <-> *ptr::mut_offset(p, i);
} }
} }
@ -709,9 +706,7 @@ pub fn dedup<T:Eq>(v: &mut ~[T]) {
// last_written < next_to_read < ln // last_written < next_to_read < ln
if *ptr::mut_offset(p, next_to_read) == if *ptr::mut_offset(p, next_to_read) ==
*ptr::mut_offset(p, last_written) { *ptr::mut_offset(p, last_written) {
// FIXME #4204 Should be uninit() - don't need to let mut dropped = intrinsics::uninit();
// zero
let mut dropped = intrinsics::init();
dropped <-> *ptr::mut_offset(p, next_to_read); dropped <-> *ptr::mut_offset(p, next_to_read);
} else { } else {
last_written += 1; last_written += 1;

View file

@ -139,7 +139,7 @@ pub impl <T:Ord> PriorityQueue<T> {
while pos > start { while pos > start {
let parent = (pos - 1) >> 1; let parent = (pos - 1) >> 1;
if new > self.data[parent] { if new > self.data[parent] {
let mut x = rusti::init(); let mut x = rusti::uninit();
x <-> self.data[parent]; x <-> self.data[parent];
rusti::move_val_init(&mut self.data[pos], x); rusti::move_val_init(&mut self.data[pos], x);
pos = parent; pos = parent;
@ -162,7 +162,7 @@ pub impl <T:Ord> PriorityQueue<T> {
if right < end && !(self.data[child] > self.data[right]) { if right < end && !(self.data[child] > self.data[right]) {
child = right; child = right;
} }
let mut x = rusti::init(); let mut x = rusti::uninit();
x <-> self.data[child]; x <-> self.data[child];
rusti::move_val_init(&mut self.data[pos], x); rusti::move_val_init(&mut self.data[pos], x);
pos = child; pos = child;

View file

@ -51,7 +51,7 @@ impl<T: Owned> Drop for Rc<T> {
unsafe { unsafe {
(*self.ptr).count -= 1; (*self.ptr).count -= 1;
if (*self.ptr).count == 0 { if (*self.ptr).count == 0 {
let mut x = intrinsics::init(); let mut x = intrinsics::uninit();
x <-> *self.ptr; x <-> *self.ptr;
free(self.ptr as *c_void) free(self.ptr as *c_void)
} }
@ -159,7 +159,7 @@ impl<T: Owned> Drop for RcMut<T> {
unsafe { unsafe {
(*self.ptr).count -= 1; (*self.ptr).count -= 1;
if (*self.ptr).count == 0 { if (*self.ptr).count == 0 {
let mut x = rusti::init(); let mut x = rusti::uninit();
x <-> *self.ptr; x <-> *self.ptr;
free(self.ptr as *c_void) free(self.ptr as *c_void)
} }