From 5d620dc0e4909a624ef3fe4f78af4d8be4827393 Mon Sep 17 00:00:00 2001 From: Liam Gray Date: Thu, 28 Nov 2024 13:22:13 +0000 Subject: [PATCH] perf: inlining specializable methods Signed-off-by: Liam Gray --- ciborium-ll/src/enc.rs | 5 ++++- ciborium-ll/src/hdr.rs | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ciborium-ll/src/enc.rs b/ciborium-ll/src/enc.rs index 660f96e..5b30f69 100644 --- a/ciborium-ll/src/enc.rs +++ b/ciborium-ll/src/enc.rs @@ -18,10 +18,12 @@ impl From for Encoder { impl Write for Encoder { 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() } @@ -29,12 +31,13 @@ impl Write for Encoder { impl Encoder { /// 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); diff --git a/ciborium-ll/src/hdr.rs b/ciborium-ll/src/hdr.rs index dec1788..b6dcac2 100644 --- a/ciborium-ll/src/hdr.rs +++ b/ciborium-ll/src/hdr.rs @@ -75,6 +75,7 @@ pub enum Header { impl TryFrom for Header { type Error = InvalidError; + #[inline] fn try_from(title: Title) -> Result<Self, Self::Error> { let opt = |minor| { Some(match minor { @@ -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),