Skip to content

Commit 0318b1b

Browse files
committed
add missing #[inline] attributes for f32 and f64 in primitive.rs
I testing this change on the following simple program: ``` pub mod primlist_capnp { include!(concat!(env!("OUT_DIR"), "/primlist_capnp.rs")); } pub fn main() { let mut scratch_space = vec![0u8; 16000]; let mut input: Vec<f64>= vec![0.0;1500]; let mut cc = 1.1; for _ in 0 .. 500000 { for inp in &mut input[..] { *inp = cc; cc += 0.02; } cc -= input.len() as f64 * 0.02; cc += 0.001; let allocator = capnp::message::ScratchSpaceHeapAllocator::new(&mut scratch_space); let mut message = ::capnp::message::Builder::new(allocator); let root : primlist_capnp::foo::Builder = message.init_root(); let mut list = root.init_float_list(input.len() as u32); for (i,n) in input.iter().enumerate() { list.set(i as u32,*n); } for (i,n) in input.iter().enumerate() { assert_eq!(*n, list.get(i as u32)); } } } ``` Adding the #[inline] attribute cut the run time from ~2.5 seconds to about 1.0 seconds.
1 parent 5d7519a commit 0318b1b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

capnp/src/private/primitive.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ primitive_impl!(f64, 8);
6565
impl Primitive for f32 {
6666
type Raw = Self;
6767

68+
#[inline]
6869
fn get(raw: &Self::Raw) -> Self {
6970
Self::from_bits(raw.to_bits().to_le())
7071
}
7172

73+
#[inline]
7274
fn set(raw: &mut Self::Raw, value: Self) {
7375
*raw = Self::from_bits(value.to_bits().to_le())
7476
}
@@ -78,10 +80,12 @@ impl Primitive for f32 {
7880
impl Primitive for f64 {
7981
type Raw = Self;
8082

83+
#[inline]
8184
fn get(raw: &Self::Raw) -> Self {
8285
Self::from_bits(raw.to_bits().to_le())
8386
}
8487

88+
#[inline]
8589
fn set(raw: &mut Self::Raw, value: Self) {
8690
*raw = Self::from_bits(value.to_bits().to_le())
8791
}

0 commit comments

Comments
 (0)