Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggressive inlining (+20% serialization speed boost) #147

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading