From dd1bc5b89873295d4e81f7a93624963e99586c17 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sat, 30 Sep 2023 14:15:48 -0400 Subject: [PATCH] printer: sprinkle in a few #[inline] annotations These seem to help when ripgrep emits a lot of output, especially when the --column flag is used. --- crates/printer/src/counter.rs | 29 ++++++++++++++--------------- crates/printer/src/hyperlink.rs | 1 + 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/printer/src/counter.rs b/crates/printer/src/counter.rs index a9f5af16..3f74d935 100644 --- a/crates/printer/src/counter.rs +++ b/crates/printer/src/counter.rs @@ -20,78 +20,77 @@ impl CounterWriter { impl CounterWriter { /// Returns the total number of bytes written since construction or the /// last time `reset` was called. + #[inline] pub(crate) fn count(&self) -> u64 { self.count } /// Returns the total number of bytes written since construction. + #[inline] pub(crate) fn total_count(&self) -> u64 { self.total_count + self.count } /// Resets the number of bytes written to `0`. + #[inline] pub(crate) fn reset_count(&mut self) { self.total_count += self.count; self.count = 0; } - /// Clear resets all counting related state for this writer. - /// - /// After this call, the total count of bytes written to the underlying - /// writer is erased and reset. - #[allow(dead_code)] - pub(crate) fn clear(&mut self) { - self.count = 0; - self.total_count = 0; - } - - #[allow(dead_code)] - pub(crate) fn get_ref(&self) -> &W { - &self.wtr - } - + #[inline] pub(crate) fn get_mut(&mut self) -> &mut W { &mut self.wtr } + #[inline] pub(crate) fn into_inner(self) -> W { self.wtr } } impl Write for CounterWriter { + // A high match count ad hoc benchmark flagged this as a hot spot. + #[inline(always)] fn write(&mut self, buf: &[u8]) -> Result { let n = self.wtr.write(buf)?; self.count += n as u64; Ok(n) } + #[inline] fn flush(&mut self) -> Result<(), io::Error> { self.wtr.flush() } } impl WriteColor for CounterWriter { + #[inline] fn supports_color(&self) -> bool { self.wtr.supports_color() } + #[inline] fn supports_hyperlinks(&self) -> bool { self.wtr.supports_hyperlinks() } + #[inline] fn set_color(&mut self, spec: &ColorSpec) -> io::Result<()> { self.wtr.set_color(spec) } + #[inline] fn set_hyperlink(&mut self, link: &HyperlinkSpec) -> io::Result<()> { self.wtr.set_hyperlink(link) } + #[inline] fn reset(&mut self) -> io::Result<()> { self.wtr.reset() } + #[inline] fn is_synchronous(&self) -> bool { self.wtr.is_synchronous() } diff --git a/crates/printer/src/hyperlink.rs b/crates/printer/src/hyperlink.rs index d653d14e..34ba5914 100644 --- a/crates/printer/src/hyperlink.rs +++ b/crates/printer/src/hyperlink.rs @@ -632,6 +632,7 @@ pub(crate) struct InterpolatorStatus { impl InterpolatorStatus { /// Create an inactive interpolator status. + #[inline] pub(crate) fn inactive() -> InterpolatorStatus { InterpolatorStatus { active: false } }