diff --git a/src/cmd/apply.rs b/src/cmd/apply.rs index fbd70b20a..12b6562f1 100644 --- a/src/cmd/apply.rs +++ b/src/cmd/apply.rs @@ -321,6 +321,7 @@ use rayon::{ }; use regex::Regex; use serde::Deserialize; +use smallvec::SmallVec; use strsim::{ damerau_levenshtein, hamming, jaro_winkler, normalized_damerau_levenshtein, osa_distance, sorensen_dice, @@ -508,7 +509,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> { String::new() }; - let mut ops_vec: Vec = Vec::new(); + let mut ops_vec = SmallVec::<[Operations; 4]>::new(); let apply_cmd = if args.cmd_operations { match validate_operations( @@ -727,7 +728,7 @@ fn validate_operations( flag_replacement: &str, flag_new_column: Option<&String>, flag_formatstr: &str, -) -> Result, CliError> { +) -> Result, CliError> { let mut censor_invokes = 0_u8; let mut copy_invokes = 0_u8; let mut eudex_invokes = 0_u8; @@ -738,7 +739,7 @@ fn validate_operations( let mut strip_invokes = 0_u8; let mut whatlang_invokes = 0_u8; - let mut ops_vec: Vec = Vec::with_capacity(operations.len()); + let mut ops_vec = SmallVec::with_capacity(operations.len()); for op in operations { let Ok(operation) = Operations::from_str(op) else { @@ -960,7 +961,7 @@ fn validate_operations( #[inline] fn apply_operations( - ops_vec: &Vec, + ops_vec: &SmallVec<[Operations; 4]>, cell: &mut String, comparand: &str, replacement: &str, diff --git a/src/cmd/applydp.rs b/src/cmd/applydp.rs index f4e9215e7..fa42f80d6 100644 --- a/src/cmd/applydp.rs +++ b/src/cmd/applydp.rs @@ -193,6 +193,7 @@ use rayon::{ }; use regex::Regex; use serde::Deserialize; +use smallvec::SmallVec; use strum_macros::EnumString; use crate::{ @@ -331,7 +332,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> { EmptyReplace, } - let mut ops_vec: Vec = Vec::new(); + let mut ops_vec = SmallVec::<[Operations; 4]>::new(); let applydp_cmd = if args.cmd_operations { match validate_operations( @@ -496,13 +497,13 @@ fn validate_operations( flag_replacement: &str, flag_new_column: &Option, flag_formatstr: &str, -) -> Result, CliError> { +) -> Result, CliError> { let mut copy_invokes = 0_u8; let mut regex_replace_invokes = 0_u8; let mut replace_invokes = 0_u8; let mut strip_invokes = 0_u8; - let mut ops_vec: Vec = Vec::with_capacity(operations.len()); + let mut ops_vec = SmallVec::with_capacity(operations.len()); for op in operations { let Ok(operation) = Operations::from_str(op) else { @@ -587,7 +588,7 @@ fn validate_operations( #[inline] fn applydp_operations( - ops_vec: &Vec, + ops_vec: &SmallVec<[Operations; 4]>, cell: &mut String, comparand: &str, replacement: &str,