From 3d897d508e83d6a35ab7f12da5d69c6690afbc2e Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Tue, 17 Oct 2023 04:38:20 -0400 Subject: [PATCH] `cat`: replace `byte_records()` with faster `read_byte_record()` as we can reuse the row byterecord allocation in this hot loop --- src/cmd/cat.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cmd/cat.rs b/src/cmd/cat.rs index 12fefe520..ed518e515 100644 --- a/src/cmd/cat.rs +++ b/src/cmd/cat.rs @@ -158,7 +158,7 @@ impl Args { let mut rdr; let mut header: &csv::ByteRecord; let mut columns_of_this_file = IndexMap::with_capacity(num_columns_global); - let mut row: csv::ByteRecord; + let mut row: csv::ByteRecord = csv::ByteRecord::new(); for conf in self.configs()? { if conf.is_stdin() { @@ -195,8 +195,7 @@ impl Args { .to_string_lossy() .to_string(); - for current_row in rdr.byte_records() { - row = current_row?; + while rdr.read_byte_record(&mut row)? { for (col_idx, c) in columns_global.iter().enumerate() { if let Some(idx) = columns_of_this_file.get(c) { if let Some(d) = row.get(*idx) {