Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline Finallyalizer::drop, allowing LLVM to optimize finally. #10918

Merged
merged 1 commit into from
Dec 14, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libstd/unstable/finally.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct Finallyalizer<'a> {

#[unsafe_destructor]
impl<'a> Drop for Finallyalizer<'a> {
#[inline]
fn drop(&mut self) {
(self.dtor)();
}
Expand Down
55 changes: 55 additions & 0 deletions src/libstd/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4217,6 +4217,7 @@ mod bench {
use vec;
use vec::VectorVector;
use option::*;
use ptr;

#[bench]
fn iterator(bh: &mut BenchHarness) {
Expand Down Expand Up @@ -4339,4 +4340,58 @@ mod bench {
vec.contains(&99u);
})
}

#[bench]
fn zero_1kb_from_elem(bh: &mut BenchHarness) {
bh.iter(|| {
let _v: ~[u8] = vec::from_elem(1024, 0u8);
});
}

#[bench]
fn zero_1kb_set_memory(bh: &mut BenchHarness) {
bh.iter(|| {
let mut v: ~[u8] = vec::with_capacity(1024);
unsafe {
let vp = vec::raw::to_mut_ptr(v);
ptr::set_memory(vp, 0, 1024);
vec::raw::set_len(&mut v, 1024);
}
});
}

#[bench]
fn zero_1kb_fixed_repeat(bh: &mut BenchHarness) {
bh.iter(|| {
let _v: ~[u8] = ~[0u8, ..1024];
});
}

#[bench]
fn zero_1kb_loop_set(bh: &mut BenchHarness) {
// Slower because the { len, cap, [0 x T] }* repr allows a pointer to the length
// field to be aliased (in theory) and prevents LLVM from optimizing loads away.
bh.iter(|| {
let mut v: ~[u8] = vec::with_capacity(1024);
unsafe {
vec::raw::set_len(&mut v, 1024);
}
for i in range(0, 1024) {
v[i] = 0;
}
});
}

#[bench]
fn zero_1kb_mut_iter(bh: &mut BenchHarness) {
bh.iter(|| {
let mut v: ~[u8] = vec::with_capacity(1024);
unsafe {
vec::raw::set_len(&mut v, 1024);
}
for x in v.mut_iter() {
*x = 0;
}
});
}
}