From f9bc99f31c3fe61b1403f72c62c8295e16577e67 Mon Sep 17 00:00:00 2001 From: wcampbell Date: Fri, 8 Dec 2023 21:39:05 -0500 Subject: [PATCH] More inline --- deku-derive/src/macros/deku_read.rs | 3 +++ src/impls/primitive.rs | 38 ++++++++++++++--------------- src/reader.rs | 2 +- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/deku-derive/src/macros/deku_read.rs b/deku-derive/src/macros/deku_read.rs index 40ec19fd..7df21290 100644 --- a/deku-derive/src/macros/deku_read.rs +++ b/deku-derive/src/macros/deku_read.rs @@ -127,6 +127,7 @@ fn emit_struct(input: &DekuData) -> Result { tokens.extend(quote! { impl #imp ::#crate_::DekuReader<#lifetime> for #ident #wher { + #[inline(always)] fn from_reader_with_ctx(__deku_reader: &mut ::#crate_::reader::Reader, _: ()) -> core::result::Result { #read_body } @@ -373,6 +374,7 @@ fn emit_enum(input: &DekuData) -> Result { tokens.extend(quote! { #[allow(non_snake_case)] impl #imp ::#crate_::DekuReader<#lifetime, #ctx_types> for #ident #wher { + #[inline(always)] fn from_reader_with_ctx(__deku_reader: &mut ::#crate_::reader::Reader, #ctx_arg) -> core::result::Result { #read_body } @@ -385,6 +387,7 @@ fn emit_enum(input: &DekuData) -> Result { tokens.extend(quote! { #[allow(non_snake_case)] impl #imp ::#crate_::DekuReader<#lifetime> for #ident #wher { + #[inline(always)] fn from_reader_with_ctx(__deku_reader: &mut ::#crate_::reader::Reader, _: ()) -> core::result::Result { #read_body } diff --git a/src/impls/primitive.rs b/src/impls/primitive.rs index 09114ac6..77ce5169 100644 --- a/src/impls/primitive.rs +++ b/src/impls/primitive.rs @@ -60,7 +60,7 @@ where // specialize u8 for ByteSize impl DekuRead<'_, (Endian, ByteSize)> for u8 { - #[inline] + #[inline(always)] fn read( input: &BitSlice, (_, _): (Endian, ByteSize), @@ -74,7 +74,7 @@ impl DekuRead<'_, (Endian, ByteSize)> for u8 { } impl DekuReader<'_, (Endian, ByteSize)> for u8 { - #[inline] + #[inline(always)] fn from_reader_with_ctx( reader: &mut Reader, (endian, size): (Endian, ByteSize), @@ -98,7 +98,7 @@ impl DekuReader<'_, (Endian, ByteSize)> for u8 { macro_rules! ImplDekuReadBits { ($typ:ty, $inner:ty) => { impl DekuRead<'_, (Endian, BitSize)> for $typ { - #[inline] + #[inline(always)] fn read( input: &BitSlice, (endian, size): (Endian, BitSize), @@ -174,7 +174,7 @@ macro_rules! ImplDekuReadBits { } impl DekuReader<'_, (Endian, BitSize)> for $typ { - #[inline] + #[inline(always)] fn from_reader_with_ctx( reader: &mut Reader, (endian, size): (Endian, BitSize), @@ -200,7 +200,7 @@ macro_rules! ImplDekuReadBits { macro_rules! ImplDekuReadBytes { ($typ:ty, $inner:ty) => { impl DekuRead<'_, (Endian, ByteSize)> for $typ { - #[inline] + #[inline(always)] fn read( input: &BitSlice, (endian, size): (Endian, ByteSize), @@ -223,7 +223,7 @@ macro_rules! ImplDekuReadBytes { } impl DekuReader<'_, (Endian, ByteSize)> for $typ { - #[inline] + #[inline(always)] fn from_reader_with_ctx( reader: &mut Reader, (endian, size): (Endian, ByteSize), @@ -267,7 +267,7 @@ macro_rules! ImplDekuReadBytes { macro_rules! ImplDekuReadSignExtend { ($typ:ty, $inner:ty) => { impl DekuRead<'_, (Endian, ByteSize)> for $typ { - #[inline] + #[inline(always)] fn read( input: &BitSlice, (endian, size): (Endian, ByteSize), @@ -284,7 +284,7 @@ macro_rules! ImplDekuReadSignExtend { } impl DekuReader<'_, (Endian, ByteSize)> for $typ { - #[inline] + #[inline(always)] fn from_reader_with_ctx( reader: &mut Reader, (endian, size): (Endian, ByteSize), @@ -317,7 +317,7 @@ macro_rules! ImplDekuReadSignExtend { } impl DekuRead<'_, (Endian, BitSize)> for $typ { - #[inline] + #[inline(always)] fn read( input: &BitSlice, (endian, size): (Endian, BitSize), @@ -334,7 +334,7 @@ macro_rules! ImplDekuReadSignExtend { } impl DekuReader<'_, (Endian, BitSize)> for $typ { - #[inline] + #[inline(always)] fn from_reader_with_ctx( reader: &mut Reader, (endian, size): (Endian, BitSize), @@ -363,7 +363,7 @@ macro_rules! ForwardDekuRead { ($typ:ty) => { // Only have `endian`, set `bit_size` to `Size::of::()` impl DekuReader<'_, Endian> for $typ { - #[inline] + #[inline(always)] fn from_reader_with_ctx( reader: &mut Reader, endian: Endian, @@ -376,7 +376,7 @@ macro_rules! ForwardDekuRead { // Only have `byte_size`, set `endian` to `Endian::default`. impl DekuReader<'_, ByteSize> for $typ { - #[inline] + #[inline(always)] fn from_reader_with_ctx( reader: &mut Reader, byte_size: ByteSize, @@ -390,7 +390,7 @@ macro_rules! ForwardDekuRead { //// Only have `bit_size`, set `endian` to `Endian::default`. impl DekuReader<'_, BitSize> for $typ { - #[inline] + #[inline(always)] fn from_reader_with_ctx( reader: &mut Reader, bit_size: BitSize, @@ -406,7 +406,7 @@ macro_rules! ForwardDekuRead { } impl DekuReader<'_> for $typ { - #[inline] + #[inline(always)] fn from_reader_with_ctx( reader: &mut Reader, _: (), @@ -420,7 +420,7 @@ macro_rules! ForwardDekuRead { macro_rules! ImplDekuWrite { ($typ:ty) => { impl DekuWriter<(Endian, BitSize)> for $typ { - #[inline] + #[inline(always)] fn to_writer( &self, writer: &mut Writer, @@ -466,7 +466,7 @@ macro_rules! ImplDekuWrite { } impl DekuWriter<(Endian, ByteSize)> for $typ { - #[inline] + #[inline(always)] fn to_writer( &self, writer: &mut Writer, @@ -517,7 +517,7 @@ macro_rules! ImplDekuWrite { macro_rules! ForwardDekuWrite { ($typ:ty) => { impl DekuWriter for $typ { - #[inline] + #[inline(always)] fn to_writer( &self, writer: &mut Writer, @@ -528,7 +528,7 @@ macro_rules! ForwardDekuWrite { } impl DekuWriter for $typ { - #[inline] + #[inline(always)] fn to_writer( &self, writer: &mut Writer, @@ -539,7 +539,7 @@ macro_rules! ForwardDekuWrite { } impl DekuWriter for $typ { - #[inline] + #[inline(always)] fn to_writer(&self, writer: &mut Writer, _: ()) -> Result<(), DekuError> { <$typ>::to_writer(self, writer, Endian::default()) } diff --git a/src/reader.rs b/src/reader.rs index aea81f63..37d59afd 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -127,7 +127,7 @@ impl<'a, R: Read> Reader<'a, R> { /// /// # Params /// `amt` - Amount of bits that will be read. Must be <= [`MAX_BITS_AMT`]. - #[inline] + #[cold] pub fn read_bits(&mut self, amt: usize) -> Result>, DekuError> { #[cfg(feature = "logging")] log::trace!("read_bits: requesting {amt} bits");