Skip to content

Commit

Permalink
frequency: optimize allocations before hot loop
Browse files Browse the repository at this point in the history
  • Loading branch information
jqnatividad committed Oct 7, 2023
1 parent f122f0c commit 655bebc
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/cmd/frequency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,14 @@ impl Args {
{
let null = &b""[..].to_vec();
let nsel = sel.normal();
let mut tabs: Vec<_> = (0..nsel.len()).map(|_| Frequencies::new()).collect();
let nsel_len = nsel.len();
let mut tabs: Vec<_> = (0..nsel_len).map(|_| Frequencies::new()).collect();

#[allow(unused_assignments)]
// amortize allocation
let mut field_work: Vec<u8> = Vec::with_capacity(100);
let mut row_work: csv::ByteRecord = csv::ByteRecord::default();
// amortize allocations
let mut field_work: Vec<u8> = Vec::with_capacity(nsel_len);
let mut row_work: csv::ByteRecord = csv::ByteRecord::with_capacity(200, nsel_len);

let flag_no_nulls = self.flag_no_nulls;
for row in it {
row_work.clone_from(&row?);
Expand Down

0 comments on commit 655bebc

Please sign in to comment.