Skip to content

Commit

Permalink
perf: inlining specializable methods
Browse files Browse the repository at this point in the history
Signed-off-by: Liam Gray <[email protected]>
  • Loading branch information
hoxxep authored and rjzak committed Nov 30, 2024
1 parent c637e7b commit 5d620dc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ciborium-ll/src/enc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,26 @@ impl<W: Write> From<W> for Encoder<W> {
impl<W: Write> Write for Encoder<W> {
type Error = W::Error;

#[inline]
fn write_all(&mut self, data: &[u8]) -> Result<(), Self::Error> {
self.0.write_all(data)
}

#[inline]
fn flush(&mut self) -> Result<(), Self::Error> {
self.0.flush()
}
}

impl<W: Write> Encoder<W> {
/// Unwraps the `Write`, consuming the `Encoder`.
#[inline]
pub fn into_inner(self) -> W {
self.0
}

/// Push a `Header` to the wire
#[inline]
#[inline(always)]
pub fn push(&mut self, header: Header) -> Result<(), W::Error> {
let title = Title::from(header);

Expand Down
2 changes: 2 additions & 0 deletions ciborium-ll/src/hdr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub enum Header {
impl TryFrom<Title> for Header {
type Error = InvalidError;

#[inline]
fn try_from(title: Title) -> Result<Self, Self::Error> {
let opt = |minor| {
Some(match minor {
Expand Down Expand Up @@ -116,6 +117,7 @@ impl TryFrom<Title> for Header {
}

impl From<Header> for Title {
#[inline(always)]
fn from(header: Header) -> Self {
let int = |i: u64| match i {
x if x <= 23 => Minor::This(i as u8),
Expand Down

0 comments on commit 5d620dc

Please sign in to comment.