Skip to content

Commit 6ed2067

Browse files
committed
Auto merge of #52206 - RalfJung:zst-slices, r=<try>
slices: fix ZST slice iterators making up pointers; debug_assert alignment in from_raw_parts This fixes the problem that we are fabricating pointers out of thin air. I also managed to share more code between the mutable and shared iterators, while reducing the amount of macros. I am not sure how useful it really is to add a `debug_assert!` in libcore. Everybody gets a release version of that anyway, right? Is there at least a CI job that runs the test suite with a debug version? Fixes #42789
2 parents 12ed235 + 924225a commit 6ed2067

File tree

3 files changed

+279
-211
lines changed

3 files changed

+279
-211
lines changed

src/libcore/benches/slice.rs

+46
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,49 @@ fn binary_search_l2_with_dups(b: &mut Bencher) {
6565
fn binary_search_l3_with_dups(b: &mut Bencher) {
6666
binary_search(b, Cache::L3, |i| i / 16 * 16);
6767
}
68+
69+
fn iter<T>(b: &mut Bencher, mapper: impl Fn(usize) -> T) {
70+
let size = 1024;
71+
let mut v = (0..size).map(mapper).collect::<Vec<T>>();
72+
b.iter(move || {
73+
let mut v = &mut v[..];
74+
black_box(&mut v);
75+
for i in v.iter() {
76+
black_box(i);
77+
}
78+
});
79+
}
80+
81+
fn iter_nth<T>(b: &mut Bencher, mapper: impl Fn(usize) -> T) {
82+
let size = 1024;
83+
let mut v = (0..size).map(mapper).collect::<Vec<T>>();
84+
b.iter(move || {
85+
let mut v = &mut v[..];
86+
black_box(&mut v);
87+
let mut it = v.iter();
88+
for i in 0..size {
89+
black_box(it.nth(0).unwrap());
90+
black_box(v.iter().nth(i).unwrap());
91+
}
92+
});
93+
}
94+
95+
#[bench]
96+
fn iter_usize(b: &mut Bencher) {
97+
iter(b, |i| i);
98+
}
99+
100+
#[bench]
101+
fn iter_zst(b: &mut Bencher) {
102+
iter(b, |_i| ());
103+
}
104+
105+
#[bench]
106+
fn iter_nth_usize(b: &mut Bencher) {
107+
iter_nth(b, |i| i);
108+
}
109+
110+
#[bench]
111+
fn iter_nth_zst(b: &mut Bencher) {
112+
iter_nth(b, |_i| ());
113+
}

0 commit comments

Comments
 (0)