Skip to content

Commit 006a0b3

Browse files
A couple of adjustments for the main demo and one of the benchmarks
1 parent ab1ced6 commit 006a0b3

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

benchmark/heap_suite.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn staticheap_push_random_u64_512(b: &mut Bencher) {
1919
.unwrap()
2020
.as_nanos(),
2121
);
22-
let vec = StaticVec::<u64, 512>::filled_with(|| rng.rand_range(1..769));
22+
let vec = StaticVec::<u64, 512>::filled_with(|| rng.rand_range(1..641));
2323
let mut heap = StaticHeap::<u64, 512>::new();
2424
b.iter(|| {
2525
for item in &vec {
@@ -37,7 +37,7 @@ fn staticheap_push_random_u64_1024(b: &mut Bencher) {
3737
.unwrap()
3838
.as_nanos(),
3939
);
40-
let vec = StaticVec::<u64, 1024>::filled_with(|| rng.rand_range(1..1537));
40+
let vec = StaticVec::<u64, 1024>::filled_with(|| rng.rand_range(1..1281));
4141
let mut heap = StaticHeap::<u64, 1024>::new();
4242
b.iter(|| {
4343
for item in &vec {
@@ -55,7 +55,7 @@ fn staticheap_push_random_u64_2048(b: &mut Bencher) {
5555
.unwrap()
5656
.as_nanos(),
5757
);
58-
let vec = StaticVec::<u64, 2048>::filled_with(|| rng.rand_range(1..3073));
58+
let vec = StaticVec::<u64, 2048>::filled_with(|| rng.rand_range(1..2561));
5959
let mut heap = StaticHeap::<u64, 2048>::new();
6060
b.iter(|| {
6161
for item in &vec {
@@ -73,7 +73,7 @@ fn staticheap_push_random_u64_4096(b: &mut Bencher) {
7373
.unwrap()
7474
.as_nanos(),
7575
);
76-
let vec = StaticVec::<u64, 4096>::filled_with(|| rng.rand_range(1..6145));
76+
let vec = StaticVec::<u64, 4096>::filled_with(|| rng.rand_range(1..5121));
7777
let mut heap = StaticHeap::<u64, 4096>::new();
7878
b.iter(|| {
7979
for item in &vec {
@@ -91,7 +91,7 @@ fn staticheap_push_random_u64_8192(b: &mut Bencher) {
9191
.unwrap()
9292
.as_nanos(),
9393
);
94-
let vec = StaticVec::<u64, 8192>::filled_with(|| rng.rand_range(1..12289));
94+
let vec = StaticVec::<u64, 8192>::filled_with(|| rng.rand_range(1..10241));
9595
let mut heap = StaticHeap::<u64, 8192>::new();
9696
b.iter(|| {
9797
for item in &vec {

demo/main_demo.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,28 +112,28 @@ const BUILT_AS_WELL: StaticVec<MyStruct, 3> =
112112
// You can even do quite a bit with a StaticVec inside of a top-level const block.
113113
static BLOCKY: StaticVec<MyOtherStruct, 6> = const {
114114
let mut a = staticvec![
115+
MyOtherStruct { s: "a" },
116+
MyOtherStruct { s: "b" },
117+
MyOtherStruct { s: "c" },
118+
];
119+
let b = staticvec![
115120
MyOtherStruct { s: "d" },
116121
MyOtherStruct { s: "e" },
117122
MyOtherStruct { s: "f" }
118123
];
119-
let mut b = StaticVec::<MyOtherStruct, 6>::new();
120-
let iter_slice = staticvec![
121-
MyOtherStruct { s: "a" },
122-
MyOtherStruct { s: "b" },
123-
MyOtherStruct { s: "c" },
124-
]
125-
.iter()
126-
.as_slice();
127-
b.insert(0, iter_slice[0].clone());
128-
b.insert(1, iter_slice[1].clone());
129-
b.insert(2, iter_slice[2].clone());
130-
b.append(&mut a);
131-
// `a` is now empty, but we have to "forget" it anyways to make this work in a const context in
132-
// conjunction with the `const_precise_live_drops` feature currently. Note that the reason the
133-
// `build` const fn did not require any use of `mem::forget` is that we only created a single
134-
// StaticVec instance within it which was directly used as the return value.
124+
let mut c = StaticVec::<MyOtherStruct, 6>::new();
125+
let iter_slice = b.iter().as_slice();
126+
c.insert(0, iter_slice[0].clone());
127+
c.insert(1, iter_slice[1].clone());
128+
c.insert(2, iter_slice[2].clone());
129+
c.append(&mut a);
130+
// `a` is now empty, but we have to "forget" it and `b` anyways to make this work in a const
131+
// context in conjunction with the `const_precise_live_drops` feature currently. Note that the
132+
// reason the `build` const fn did not require any use of `mem::forget` is that we only created
133+
// a single StaticVec instance within it which was directly used as the return value.
135134
forget(a);
136-
b
135+
forget(b);
136+
c
137137
};
138138

139139
static BLOCKIER: StaticVec<i32, 12> = const {

0 commit comments

Comments
 (0)