Backport official GLib iterator safety fix for Linux desktop
This commit is contained in:
1 parent
43c43ebdc9
commit
8ef874c609
133 files changed
+55342
-2
No files matched your search
@@ -0,0 +1,46 @@
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use glib::IntoGStr;
|
||||
|
||||
pub fn str_into_gstr(c: &mut Criterion) {
|
||||
c.bench_function("str as IntoGStr", |b| {
|
||||
b.iter(|| {
|
||||
"abcdefg".run_with_gstr(|g| {
|
||||
black_box(g);
|
||||
})
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
pub fn string_into_gstr(c: &mut Criterion) {
|
||||
c.bench_function("String as IntoGStr", |b| {
|
||||
b.iter(|| {
|
||||
let mut s = String::from("abcdefg");
|
||||
s.shrink_to_fit();
|
||||
assert_eq!(s.capacity(), s.len());
|
||||
s.run_with_gstr(|g| {
|
||||
black_box(g);
|
||||
})
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
pub fn string_with_capacity_into_gstr(c: &mut Criterion) {
|
||||
c.bench_function("String::with_capacity as IntoGStr", |b| {
|
||||
b.iter(|| {
|
||||
let mut s = String::with_capacity(100);
|
||||
s.push_str("abcdefg");
|
||||
assert!(s.capacity() > s.len());
|
||||
s.run_with_gstr(|g| {
|
||||
black_box(g);
|
||||
})
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(
|
||||
benches,
|
||||
str_into_gstr,
|
||||
string_into_gstr,
|
||||
string_with_capacity_into_gstr
|
||||
);
|
||||
criterion_main!(benches);
|
||||
Reference in new issue
Block a user