Skip to content

Commit

Permalink
cat: replace byte_records() with faster read_byte_record()
Browse files Browse the repository at this point in the history
as we can reuse the row byterecord allocation in this hot loop
  • Loading branch information
jqnatividad committed Oct 17, 2023
1 parent d1e343d commit 3d897d5
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/cmd/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3d897d5

Please sign in to comment.