Skip to content

Commit 98314e2

Browse files
committed
---
yaml --- r: 36737 b: refs/heads/try2 c: 309cdfd h: refs/heads/master i: 36735: 92d5526 v: v3
1 parent bd0e96f commit 98314e2

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 2c21f348a45f593ed4452fab9d083283cd4e7ce0
8+
refs/heads/try2: 309cdfd835abb43294a4c5eadac1f5a8dfd134b5
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/src/libcore/vec.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern mod rustrt {
2929
#[abi = "rust-intrinsic"]
3030
extern mod rusti {
3131
fn move_val_init<T>(dst: &mut T, -src: T);
32+
fn init<T>() -> T;
3233
}
3334

3435

@@ -483,9 +484,15 @@ pub fn remove<T>(v: &mut ~[T], i: uint) -> T {
483484
pub fn consume<T>(v: ~[T], f: fn(uint, v: T)) unsafe {
484485
let mut v = v; // FIXME(#3488)
485486

486-
do as_imm_buf(v) |p, ln| {
487+
do as_mut_buf(v) |p, ln| {
487488
for uint::range(0, ln) |i| {
488-
let x = move *ptr::offset(p, i);
489+
// NB: This unsafe operation counts on init writing 0s to the
490+
// holes we create in the vector. That ensures that, if the
491+
// iterator fails then we won't try to clean up the consumed
492+
// elements during unwinding
493+
let mut x = rusti::init();
494+
let p = ptr::mut_offset(p, i);
495+
x <-> *p;
489496
f(i, x);
490497
}
491498
}
@@ -505,7 +512,9 @@ pub fn pop<T>(v: &mut ~[T]) -> T {
505512
}
506513
let valptr = ptr::to_mut_unsafe_ptr(&mut v[ln - 1u]);
507514
unsafe {
508-
let val = move *valptr;
515+
// XXX: Should be rusti::uninit() - we don't need this zeroed
516+
let mut val = rusti::init();
517+
val <-> *valptr;
509518
raw::set_len(v, ln - 1u);
510519
val
511520
}
@@ -574,9 +583,11 @@ pub fn push_all_move<T>(v: &mut ~[T], rhs: ~[T]) {
574583
let mut rhs = rhs; // FIXME(#3488)
575584
reserve(v, v.len() + rhs.len());
576585
unsafe {
577-
do as_imm_buf(rhs) |p, len| {
586+
do as_mut_buf(rhs) |p, len| {
578587
for uint::range(0, len) |i| {
579-
let x = move *ptr::offset(p, i);
588+
// XXX Should be rusti::uninit() - don't need to zero
589+
let mut x = rusti::init();
590+
x <-> *ptr::mut_offset(p, i);
580591
push(v, x);
581592
}
582593
}
@@ -586,12 +597,14 @@ pub fn push_all_move<T>(v: &mut ~[T], rhs: ~[T]) {
586597

587598
/// Shorten a vector, dropping excess elements.
588599
pub fn truncate<T>(v: &mut ~[T], newlen: uint) {
589-
do as_imm_buf(*v) |p, oldlen| {
600+
do as_mut_buf(*v) |p, oldlen| {
590601
assert(newlen <= oldlen);
591602
unsafe {
592603
// This loop is optimized out for non-drop types.
593604
for uint::range(newlen, oldlen) |i| {
594-
let _dropped = move *ptr::offset(p, i);
605+
// XXX Should be rusti::uninit() - don't need to zero
606+
let mut dropped = rusti::init();
607+
dropped <-> *ptr::mut_offset(p, i);
595608
}
596609
raw::set_len(v, newlen);
597610
}
@@ -614,12 +627,14 @@ pub fn dedup<T: Eq>(v: &mut ~[T]) unsafe {
614627
// last_written < next_to_read < ln
615628
if *ptr::mut_offset(p, next_to_read) ==
616629
*ptr::mut_offset(p, last_written) {
617-
let _dropped = move *ptr::mut_offset(p, next_to_read);
630+
// XXX Should be rusti::uninit() - don't need to zero
631+
let mut dropped = rusti::init();
632+
dropped <-> *ptr::mut_offset(p, next_to_read);
618633
} else {
619634
last_written += 1;
620635
// last_written <= next_to_read < ln
621636
if next_to_read != last_written {
622-
*ptr::mut_offset(p, last_written) = move
637+
*ptr::mut_offset(p, last_written) <->
623638
*ptr::mut_offset(p, next_to_read);
624639
}
625640
}

0 commit comments

Comments
 (0)