mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-03-17 20:28:03 +02:00
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.
This commit is contained in:
parent
c9bfbe1e3d
commit
dd1bc5b898
@ -20,78 +20,77 @@ impl<W: Write> CounterWriter<W> {
|
|||||||
impl<W> CounterWriter<W> {
|
impl<W> CounterWriter<W> {
|
||||||
/// Returns the total number of bytes written since construction or the
|
/// Returns the total number of bytes written since construction or the
|
||||||
/// last time `reset` was called.
|
/// last time `reset` was called.
|
||||||
|
#[inline]
|
||||||
pub(crate) fn count(&self) -> u64 {
|
pub(crate) fn count(&self) -> u64 {
|
||||||
self.count
|
self.count
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the total number of bytes written since construction.
|
/// Returns the total number of bytes written since construction.
|
||||||
|
#[inline]
|
||||||
pub(crate) fn total_count(&self) -> u64 {
|
pub(crate) fn total_count(&self) -> u64 {
|
||||||
self.total_count + self.count
|
self.total_count + self.count
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resets the number of bytes written to `0`.
|
/// Resets the number of bytes written to `0`.
|
||||||
|
#[inline]
|
||||||
pub(crate) fn reset_count(&mut self) {
|
pub(crate) fn reset_count(&mut self) {
|
||||||
self.total_count += self.count;
|
self.total_count += self.count;
|
||||||
self.count = 0;
|
self.count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear resets all counting related state for this writer.
|
#[inline]
|
||||||
///
|
|
||||||
/// 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
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_mut(&mut self) -> &mut W {
|
pub(crate) fn get_mut(&mut self) -> &mut W {
|
||||||
&mut self.wtr
|
&mut self.wtr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub(crate) fn into_inner(self) -> W {
|
pub(crate) fn into_inner(self) -> W {
|
||||||
self.wtr
|
self.wtr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: Write> Write for CounterWriter<W> {
|
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> {
|
fn write(&mut self, buf: &[u8]) -> Result<usize, io::Error> {
|
||||||
let n = self.wtr.write(buf)?;
|
let n = self.wtr.write(buf)?;
|
||||||
self.count += n as u64;
|
self.count += n as u64;
|
||||||
Ok(n)
|
Ok(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn flush(&mut self) -> Result<(), io::Error> {
|
fn flush(&mut self) -> Result<(), io::Error> {
|
||||||
self.wtr.flush()
|
self.wtr.flush()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WriteColor> WriteColor for CounterWriter<W> {
|
impl<W: WriteColor> WriteColor for CounterWriter<W> {
|
||||||
|
#[inline]
|
||||||
fn supports_color(&self) -> bool {
|
fn supports_color(&self) -> bool {
|
||||||
self.wtr.supports_color()
|
self.wtr.supports_color()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn supports_hyperlinks(&self) -> bool {
|
fn supports_hyperlinks(&self) -> bool {
|
||||||
self.wtr.supports_hyperlinks()
|
self.wtr.supports_hyperlinks()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn set_color(&mut self, spec: &ColorSpec) -> io::Result<()> {
|
fn set_color(&mut self, spec: &ColorSpec) -> io::Result<()> {
|
||||||
self.wtr.set_color(spec)
|
self.wtr.set_color(spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn set_hyperlink(&mut self, link: &HyperlinkSpec) -> io::Result<()> {
|
fn set_hyperlink(&mut self, link: &HyperlinkSpec) -> io::Result<()> {
|
||||||
self.wtr.set_hyperlink(link)
|
self.wtr.set_hyperlink(link)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn reset(&mut self) -> io::Result<()> {
|
fn reset(&mut self) -> io::Result<()> {
|
||||||
self.wtr.reset()
|
self.wtr.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn is_synchronous(&self) -> bool {
|
fn is_synchronous(&self) -> bool {
|
||||||
self.wtr.is_synchronous()
|
self.wtr.is_synchronous()
|
||||||
}
|
}
|
||||||
|
@ -632,6 +632,7 @@ pub(crate) struct InterpolatorStatus {
|
|||||||
|
|
||||||
impl InterpolatorStatus {
|
impl InterpolatorStatus {
|
||||||
/// Create an inactive interpolator status.
|
/// Create an inactive interpolator status.
|
||||||
|
#[inline]
|
||||||
pub(crate) fn inactive() -> InterpolatorStatus {
|
pub(crate) fn inactive() -> InterpolatorStatus {
|
||||||
InterpolatorStatus { active: false }
|
InterpolatorStatus { active: false }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user