mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-08-05 14:42:07 -07:00
printer: hand-roll decimal formatting
It seems like a trifle, but if the match frequency is high enough, the allocation+formatting of line numbers (and columns and byte offsets) starts to matter. We squash that part of the profile in this commit by doing our own decimal formatting. I speculate that we get a speed-up from this by avoiding the formatting machinery and also a possible allocation. An alternative would be to use the `itoa` crate, and it is indeed marginally faster in ad hoc benchmarks, but I'm satisfied enough with this solution.
This commit is contained in:
@@ -5,7 +5,7 @@ use {
|
||||
termcolor::{HyperlinkSpec, WriteColor},
|
||||
};
|
||||
|
||||
use crate::hyperlink_aliases;
|
||||
use crate::{hyperlink_aliases, util::DecimalFormatter};
|
||||
|
||||
/// Hyperlink configuration.
|
||||
///
|
||||
@@ -484,11 +484,11 @@ impl Part {
|
||||
),
|
||||
Part::Path => dest.extend_from_slice(&values.path.0),
|
||||
Part::Line => {
|
||||
let line = values.line.unwrap_or(1).to_string();
|
||||
let line = DecimalFormatter::new(values.line.unwrap_or(1));
|
||||
dest.extend_from_slice(line.as_bytes());
|
||||
}
|
||||
Part::Column => {
|
||||
let column = values.column.unwrap_or(1).to_string();
|
||||
let column = DecimalFormatter::new(values.column.unwrap_or(1));
|
||||
dest.extend_from_slice(column.as_bytes());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user