Skip to content

Commit

Permalink
More inline
Browse files Browse the repository at this point in the history
  • Loading branch information
wcampbell0x2a committed Dec 28, 2023
1 parent c70f05e commit f9bc99f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
3 changes: 3 additions & 0 deletions deku-derive/src/macros/deku_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {

tokens.extend(quote! {
impl #imp ::#crate_::DekuReader<#lifetime> for #ident #wher {
#[inline(always)]
fn from_reader_with_ctx<R: ::#crate_::no_std_io::Read>(__deku_reader: &mut ::#crate_::reader::Reader<R>, _: ()) -> core::result::Result<Self, ::#crate_::DekuError> {
#read_body
}
Expand Down Expand Up @@ -373,6 +374,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
tokens.extend(quote! {
#[allow(non_snake_case)]
impl #imp ::#crate_::DekuReader<#lifetime, #ctx_types> for #ident #wher {
#[inline(always)]
fn from_reader_with_ctx<R: ::#crate_::no_std_io::Read>(__deku_reader: &mut ::#crate_::reader::Reader<R>, #ctx_arg) -> core::result::Result<Self, ::#crate_::DekuError> {
#read_body
}
Expand All @@ -385,6 +387,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
tokens.extend(quote! {
#[allow(non_snake_case)]
impl #imp ::#crate_::DekuReader<#lifetime> for #ident #wher {
#[inline(always)]
fn from_reader_with_ctx<R: ::#crate_::no_std_io::Read>(__deku_reader: &mut ::#crate_::reader::Reader<R>, _: ()) -> core::result::Result<Self, ::#crate_::DekuError> {
#read_body
}
Expand Down
38 changes: 19 additions & 19 deletions src/impls/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ where

// specialize u8 for ByteSize
impl DekuRead<'_, (Endian, ByteSize)> for u8 {
#[inline]
#[inline(always)]
fn read(
input: &BitSlice<u8, Msb0>,
(_, _): (Endian, ByteSize),
Expand All @@ -74,7 +74,7 @@ impl DekuRead<'_, (Endian, ByteSize)> for u8 {
}

impl DekuReader<'_, (Endian, ByteSize)> for u8 {
#[inline]
#[inline(always)]
fn from_reader_with_ctx<R: Read>(
reader: &mut Reader<R>,
(endian, size): (Endian, ByteSize),
Expand All @@ -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<u8, Msb0>,
(endian, size): (Endian, BitSize),
Expand Down Expand Up @@ -174,7 +174,7 @@ macro_rules! ImplDekuReadBits {
}

impl DekuReader<'_, (Endian, BitSize)> for $typ {
#[inline]
#[inline(always)]
fn from_reader_with_ctx<R: Read>(
reader: &mut Reader<R>,
(endian, size): (Endian, BitSize),
Expand All @@ -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<u8, Msb0>,
(endian, size): (Endian, ByteSize),
Expand All @@ -223,7 +223,7 @@ macro_rules! ImplDekuReadBytes {
}

impl DekuReader<'_, (Endian, ByteSize)> for $typ {
#[inline]
#[inline(always)]
fn from_reader_with_ctx<R: Read>(
reader: &mut Reader<R>,
(endian, size): (Endian, ByteSize),
Expand Down Expand Up @@ -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<u8, Msb0>,
(endian, size): (Endian, ByteSize),
Expand All @@ -284,7 +284,7 @@ macro_rules! ImplDekuReadSignExtend {
}

impl DekuReader<'_, (Endian, ByteSize)> for $typ {
#[inline]
#[inline(always)]
fn from_reader_with_ctx<R: Read>(
reader: &mut Reader<R>,
(endian, size): (Endian, ByteSize),
Expand Down Expand Up @@ -317,7 +317,7 @@ macro_rules! ImplDekuReadSignExtend {
}

impl DekuRead<'_, (Endian, BitSize)> for $typ {
#[inline]
#[inline(always)]
fn read(
input: &BitSlice<u8, Msb0>,
(endian, size): (Endian, BitSize),
Expand All @@ -334,7 +334,7 @@ macro_rules! ImplDekuReadSignExtend {
}

impl DekuReader<'_, (Endian, BitSize)> for $typ {
#[inline]
#[inline(always)]
fn from_reader_with_ctx<R: Read>(
reader: &mut Reader<R>,
(endian, size): (Endian, BitSize),
Expand Down Expand Up @@ -363,7 +363,7 @@ macro_rules! ForwardDekuRead {
($typ:ty) => {
// Only have `endian`, set `bit_size` to `Size::of::<Type>()`
impl DekuReader<'_, Endian> for $typ {
#[inline]
#[inline(always)]
fn from_reader_with_ctx<R: Read>(
reader: &mut Reader<R>,
endian: Endian,
Expand All @@ -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<R: Read>(
reader: &mut Reader<R>,
byte_size: ByteSize,
Expand All @@ -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<R: Read>(
reader: &mut Reader<R>,
bit_size: BitSize,
Expand All @@ -406,7 +406,7 @@ macro_rules! ForwardDekuRead {
}

impl DekuReader<'_> for $typ {
#[inline]
#[inline(always)]
fn from_reader_with_ctx<R: Read>(
reader: &mut Reader<R>,
_: (),
Expand All @@ -420,7 +420,7 @@ macro_rules! ForwardDekuRead {
macro_rules! ImplDekuWrite {
($typ:ty) => {
impl DekuWriter<(Endian, BitSize)> for $typ {
#[inline]
#[inline(always)]
fn to_writer<W: Write>(
&self,
writer: &mut Writer<W>,
Expand Down Expand Up @@ -466,7 +466,7 @@ macro_rules! ImplDekuWrite {
}

impl DekuWriter<(Endian, ByteSize)> for $typ {
#[inline]
#[inline(always)]
fn to_writer<W: Write>(
&self,
writer: &mut Writer<W>,
Expand Down Expand Up @@ -517,7 +517,7 @@ macro_rules! ImplDekuWrite {
macro_rules! ForwardDekuWrite {
($typ:ty) => {
impl DekuWriter<BitSize> for $typ {
#[inline]
#[inline(always)]
fn to_writer<W: Write>(
&self,
writer: &mut Writer<W>,
Expand All @@ -528,7 +528,7 @@ macro_rules! ForwardDekuWrite {
}

impl DekuWriter<ByteSize> for $typ {
#[inline]
#[inline(always)]
fn to_writer<W: Write>(
&self,
writer: &mut Writer<W>,
Expand All @@ -539,7 +539,7 @@ macro_rules! ForwardDekuWrite {
}

impl DekuWriter for $typ {
#[inline]
#[inline(always)]
fn to_writer<W: Write>(&self, writer: &mut Writer<W>, _: ()) -> Result<(), DekuError> {
<$typ>::to_writer(self, writer, Endian::default())
}
Expand Down
2 changes: 1 addition & 1 deletion src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<BitVec<u8, Msb0>>, DekuError> {
#[cfg(feature = "logging")]
log::trace!("read_bits: requesting {amt} bits");
Expand Down

0 comments on commit f9bc99f

Please sign in to comment.