From d3bd38ba13dd9bebfa5554348baeaf92673650e7 Mon Sep 17 00:00:00 2001 From: Michael Pfaff Date: Tue, 6 Sep 2022 07:47:11 -0400 Subject: [PATCH] Some changes --- src/context.rs | 11 ++++------- src/lib.rs | 1 - src/report.rs | 5 +++++ src/termination.rs | 2 ++ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/context.rs b/src/context.rs index 8152020..14f308a 100644 --- a/src/context.rs +++ b/src/context.rs @@ -47,17 +47,15 @@ impl IntoContext for Context { } /// Chains another piece of context that is equal from a hierarchical perspective. - // TODO: should this inline? Would the compiler be allowed to fold the allocations into a - // single one with inlining? + #[inline] fn chain(self, other: impl IntoContext) -> Self { - let items = match self { + Context(ContextInner::Compound(match self { Context(ContextInner::Compound(mut items)) => { items.push(other.into_context()); items } _ => vec![self, other.into_context()], - }; - Context(ContextInner::Compound(items)) + })) } } @@ -76,8 +74,7 @@ impl IntoContext for &'static str { } impl IntoContext for Cow<'static, str> { - // TODO: should this always inline? - #[inline] + #[inline(always)] fn into_context(self) -> Context { Context(ContextInner::String(self)) } diff --git a/src/lib.rs b/src/lib.rs index 8c9e949..3ec808f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ #![doc = include_str!("../README.md")] #![forbid(unsafe_code)] -#![cfg_attr(feature = "backtrace", feature(backtrace))] mod sealed; pub(crate) use sealed::seal; diff --git a/src/report.rs b/src/report.rs index 2f56a4e..010336d 100644 --- a/src/report.rs +++ b/src/report.rs @@ -25,6 +25,7 @@ impl ReportOpts { self } + #[inline] fn should_indent(&self) -> bool { self.was_nl } @@ -37,6 +38,7 @@ macro_rules! report_write { } pub(crate) use report_write; +#[inline] fn write_indent(n: usize, f: &mut impl Write) -> std::fmt::Result { for _ in 0..n { f.write_str(" ")?; @@ -54,6 +56,7 @@ impl Report for T where T: std::fmt::Display, { + #[inline(never)] fn fmt(&self, f: &mut impl Write, opts: &ReportOpts) -> std::fmt::Result { use std::fmt::Error; struct IndentedWrite<'a, W: Write> { @@ -64,6 +67,7 @@ where where W: Write, { + #[inline] fn write_str(&mut self, s: &str) -> Result<(), Error> { // TODO: any room for optimization? // iterates over the lines where each str ends with the line terminator. @@ -84,6 +88,7 @@ where Ok(()) } + #[inline] fn write_char(&mut self, c: char) -> Result<(), Error> { self.f.write_char(c)?; if c == '\n' { diff --git a/src/termination.rs b/src/termination.rs index 15b9c11..e141810 100644 --- a/src/termination.rs +++ b/src/termination.rs @@ -8,6 +8,7 @@ pub enum TerminationResult { } impl Termination for TerminationResult { + #[inline] fn report(self) -> ExitCode { match self { Self::Ok => ExitCode::SUCCESS, @@ -22,6 +23,7 @@ impl Termination for TerminationResult { } impl From> for TerminationResult { + #[inline] fn from(value: Result<(), How>) -> Self { match value { Ok(()) => Self::Ok,