Skip to content

Commit 7ffbf12

Browse files
huonwthestinger
authored andcommitted
---
yaml --- r: 65012 b: refs/heads/snap-stage3 c: fbb7cd3 h: refs/heads/master v: v3
1 parent 674bf9c commit 7ffbf12

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 54e685d4fd70eeb607668fed2026ac6cafec6107
4+
refs/heads/snap-stage3: fbb7cd32c3be0c36ff50046325a6e958d5980393
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/vec.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,11 +2141,15 @@ macro_rules! iterator {
21412141
None
21422142
} else {
21432143
let old = self.ptr;
2144-
// purposefully don't use 'ptr.offset' because for
2145-
// vectors with 0-size elements this would return the
2146-
// same pointer.
2147-
self.ptr = cast::transmute(self.ptr as uint +
2148-
sys::nonzero_size_of::<T>());
2144+
self.ptr = if sys::size_of::<T>() == 0 {
2145+
// purposefully don't use 'ptr.offset' because for
2146+
// vectors with 0-size elements this would return the
2147+
// same pointer.
2148+
cast::transmute(self.ptr as uint + 1)
2149+
} else {
2150+
self.ptr.offset(1)
2151+
};
2152+
21492153
Some(cast::transmute(old))
21502154
}
21512155
}
@@ -2171,9 +2175,12 @@ macro_rules! double_ended_iterator {
21712175
if self.end == self.ptr {
21722176
None
21732177
} else {
2174-
// See above for why 'ptr.offset' isn't used
2175-
self.end = cast::transmute(self.end as uint -
2176-
sys::nonzero_size_of::<T>());
2178+
self.end = if sys::size_of::<T>() == 0 {
2179+
// See above for why 'ptr.offset' isn't used
2180+
cast::transmute(self.end as uint - 1)
2181+
} else {
2182+
self.end.offset(-1)
2183+
};
21772184
Some(cast::transmute(self.end))
21782185
}
21792186
}
@@ -3566,3 +3573,26 @@ mod tests {
35663573
assert!(cnt == 3);
35673574
}
35683575
}
3576+
3577+
#[cfg(test)]
3578+
mod bench {
3579+
use extra::test::BenchHarness;
3580+
use vec;
3581+
use option::*;
3582+
3583+
#[bench]
3584+
fn iterator(bh: &mut BenchHarness) {
3585+
// peculiar numbers to stop LLVM from optimising the summation
3586+
// out.
3587+
let v = vec::from_fn(100, |i| i ^ (i << 1) ^ (i >> 1));
3588+
3589+
do bh.iter {
3590+
let mut sum = 0;
3591+
foreach x in v.iter() {
3592+
sum += *x;
3593+
}
3594+
// sum == 11806, to stop dead code elimination.
3595+
if sum == 0 {fail!()}
3596+
}
3597+
}
3598+
}

0 commit comments

Comments
 (0)