Skip to content

Commit

Permalink
Merge pull request #2219 from jqnatividad/smallvec_apply
Browse files Browse the repository at this point in the history
`apply` & `applydp`: use smallvec for operations vector
  • Loading branch information
jqnatividad authored Oct 19, 2024
2 parents bdb6651 + 0450193 commit cd00daa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
20 changes: 9 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ serde_json = { version = "1", features = ["preserve_order"] }
serde_stacker = { version = "0.1", optional = true }
serde_urlencoded = { version = "0.7", optional = true }
simple-expand-tilde = { version = "0.4.3", optional = true }
smallvec = "1"
snap = "1"
strsim = { version = "0.11", optional = true }
strum = { version = "0.26", features = ["phf"] }
Expand Down
9 changes: 5 additions & 4 deletions src/cmd/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -508,7 +509,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
String::new()
};

let mut ops_vec: Vec<Operations> = Vec::new();
let mut ops_vec = SmallVec::<[Operations; 4]>::new();

let apply_cmd = if args.cmd_operations {
match validate_operations(
Expand Down Expand Up @@ -727,7 +728,7 @@ fn validate_operations(
flag_replacement: &str,
flag_new_column: Option<&String>,
flag_formatstr: &str,
) -> Result<Vec<Operations>, CliError> {
) -> Result<SmallVec<[Operations; 4]>, CliError> {
let mut censor_invokes = 0_u8;
let mut copy_invokes = 0_u8;
let mut eudex_invokes = 0_u8;
Expand All @@ -738,7 +739,7 @@ fn validate_operations(
let mut strip_invokes = 0_u8;
let mut whatlang_invokes = 0_u8;

let mut ops_vec: Vec<Operations> = 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 {
Expand Down Expand Up @@ -960,7 +961,7 @@ fn validate_operations(

#[inline]
fn apply_operations(
ops_vec: &Vec<Operations>,
ops_vec: &SmallVec<[Operations; 4]>,
cell: &mut String,
comparand: &str,
replacement: &str,
Expand Down
9 changes: 5 additions & 4 deletions src/cmd/applydp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ use rayon::{
};
use regex::Regex;
use serde::Deserialize;
use smallvec::SmallVec;
use strum_macros::EnumString;

use crate::{
Expand Down Expand Up @@ -331,7 +332,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
EmptyReplace,
}

let mut ops_vec: Vec<Operations> = Vec::new();
let mut ops_vec = SmallVec::<[Operations; 4]>::new();

let applydp_cmd = if args.cmd_operations {
match validate_operations(
Expand Down Expand Up @@ -496,13 +497,13 @@ fn validate_operations(
flag_replacement: &str,
flag_new_column: &Option<String>,
flag_formatstr: &str,
) -> Result<Vec<Operations>, CliError> {
) -> Result<SmallVec<[Operations; 4]>, 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<Operations> = 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 {
Expand Down Expand Up @@ -587,7 +588,7 @@ fn validate_operations(

#[inline]
fn applydp_operations(
ops_vec: &Vec<Operations>,
ops_vec: &SmallVec<[Operations; 4]>,
cell: &mut String,
comparand: &str,
replacement: &str,
Expand Down

0 comments on commit cd00daa

Please sign in to comment.