Skip to content

Commit

Permalink
cat: optimize rowskey hot loop
Browse files Browse the repository at this point in the history
by precomputing group flag and bytes conversion outside loop
  • Loading branch information
jqnatividad committed Jan 2, 2024
1 parent 8a19abb commit 96a40e9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/cmd/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ impl Args {
GroupKind::None => {},
}

let group_flag = group_kind != GroupKind::None;
let grouping_value_bytes = grouping_value.as_bytes();

while rdr.read_byte_record(&mut row)? {
new_row.clear();
for (col_idx, c) in columns_global.iter().enumerate() {
Expand All @@ -324,10 +327,10 @@ impl Args {
} else {
new_row.push_field(b"");
}
} else if group_kind != GroupKind::None && col_idx == 0 {
} else if group_flag && col_idx == 0 {
// we are in the first column, and --group is set
// so we write the grouping value
new_row.push_field(grouping_value.as_bytes());
new_row.push_field(grouping_value_bytes);
} else {
new_row.push_field(b"");
}
Expand Down

0 comments on commit 96a40e9

Please sign in to comment.