-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodegen.rs
More file actions
28 lines (24 loc) · 783 Bytes
/
codegen.rs
File metadata and controls
28 lines (24 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#![allow(clippy::no_mangle_with_rust_abi)]
use unchecked_std::ExtendFromSliceUnchecked;
const SLICE_LEN: usize = 10;
const N_EXTENDS: usize = 16;
// CHECK-LABEL: @test_extend_from_slice
#[no_mangle]
pub fn test_extend_from_slice(xs: &[u8; SLICE_LEN]) -> Vec<u8> {
// CHECK: do_reserve_and_handle
let mut res = Vec::with_capacity(N_EXTENDS * SLICE_LEN);
for _ in 0..N_EXTENDS {
res.extend_from_slice(xs);
}
res
}
// CHECK-LABEL: @test_extend_from_slice_unchecked
#[no_mangle]
pub fn test_extend_from_slice_unchecked(xs: &[u8; SLICE_LEN]) -> Vec<u8> {
// CHECK-NOT: do_reserve_and_handle
let mut res = Vec::with_capacity(N_EXTENDS * SLICE_LEN);
for _ in 0..N_EXTENDS {
unsafe { res.extend_from_slice_unchecked(xs) };
}
res
}