231009.18 · dd1bc5b89873295d4e81f7a93624963e99586c17
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.
reading declarations
Changes to crates/printer/src/counter.rs. All files
@@ -20,78 +20,77 @@ impl<W: Write> CounterWriter<W> { impl<W> CounterWriter<W> { /// 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<W: Write> Write for CounterWriter<W> {+ // A high match count ad hoc benchmark flagged this as a hot spot.+ #[inline(always)] fn write(&mut self, buf: &[u8]) -> Result<usize, io::Error> { 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<W: WriteColor> WriteColor for CounterWriter<W> {+ #[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() }