From a3ad644dc99091eddd9546bbca3e99cf2a4b0230 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Sat, 4 Nov 2023 09:38:12 -0400 Subject: [PATCH] `cat`: use faster ahash hasher for IndexSet and IndexMap --- src/cmd/cat.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cmd/cat.rs b/src/cmd/cat.rs index 18f741b81..e2b0a71f5 100644 --- a/src/cmd/cat.rs +++ b/src/cmd/cat.rs @@ -108,15 +108,20 @@ impl Args { Ok(wtr.flush()?) } + // this algorithm is largely inspired by https://github.com/vi/csvcatrow by @vi + // https://github.com/jqnatividad/qsv/issues/527 fn cat_rowskey(&self) -> CliResult<()> { - // this algorithm is largely inspired by https://github.com/vi/csvcatrow by @vi - // https://github.com/jqnatividad/qsv/issues/527 + // ahash is a faster hasher than the default one used by IndexSet and IndexMap + type AhashIndexSet = IndexSet; + type AhashIndexMap = IndexMap; + if self.flag_no_headers { return fail_incorrectusage_clierror!( "cat rowskey does not support --no-headers, as we use column headers as keys." ); } - let mut columns_global: IndexSet> = IndexSet::with_capacity(32); + + let mut columns_global: AhashIndexSet> = AhashIndexSet::default(); if self.flag_group { columns_global.insert(self.flag_group_name.as_bytes().to_vec().into_boxed_slice()); @@ -157,7 +162,8 @@ impl Args { let mut conf_path; let mut rdr; let mut header: &csv::ByteRecord; - let mut columns_of_this_file = IndexMap::with_capacity(num_columns_global); + let mut columns_of_this_file: AhashIndexMap, usize> = AhashIndexMap::default(); + columns_of_this_file.reserve(num_columns_global); let mut row: csv::ByteRecord = csv::ByteRecord::with_capacity(500, num_columns_global); for conf in self.configs()? {