Skip to content

Commit

Permalink
Pre-allocate line buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarx committed Dec 10, 2023
1 parent 54ffd74 commit 85488c7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion helpers/rust/src/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ use std::{
io::{BufRead, BufReader},
};

/// Default capacity for the line, to avoid resizing; 128k ought to be
/// enough for any entity.
const LINE_CAPACITY: usize = 128 * 1024;

fn into_description(ordering: Ordering) -> String {
match ordering {
Ordering::Less => "newer",
Expand Down Expand Up @@ -103,7 +107,7 @@ pub(super) fn process_dump(settings: &Settings) -> Result<()> {
let dump = File::open(dump_info.path.as_path())?;
let decoder = MultiGzDecoder::new(dump);
let mut reader = BufReader::new(decoder);
let mut line = String::new();
let mut line = String::with_capacity(LINE_CAPACITY);

reader.read_line(&mut line)?;
assert_eq!(line, "[\n");
Expand Down

0 comments on commit 85488c7

Please sign in to comment.