From d5b843ff82b44b79820016b38d3c99ca76fcbdbf Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Sat, 19 Oct 2024 10:28:04 -0400 Subject: [PATCH] `applydp`: use to_owned and into_owned instead of to_string to minimize allocs --- src/cmd/applydp.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cmd/applydp.rs b/src/cmd/applydp.rs index fa42f80d6..7922846c8 100644 --- a/src/cmd/applydp.rs +++ b/src/cmd/applydp.rs @@ -596,7 +596,7 @@ fn applydp_operations( for op in ops_vec { match op { Operations::Len => { - *cell = cell.len().to_string(); + *cell = itoa::Buffer::new().format(cell.len()).to_owned(); }, Operations::Lower => { *cell = cell.to_lowercase(); @@ -606,11 +606,11 @@ fn applydp_operations( }, Operations::Squeeze => { let squeezer: &'static Regex = regex_oncelock!(r"\s+"); - *cell = squeezer.replace_all(cell, " ").to_string(); + *cell = squeezer.replace_all(cell, " ").into_owned(); }, Operations::Squeeze0 => { let squeezer: &'static Regex = regex_oncelock!(r"\s+"); - *cell = squeezer.replace_all(cell, "").to_string(); + *cell = squeezer.replace_all(cell, "").into_owned(); }, Operations::Trim => { *cell = String::from(cell.trim()); @@ -650,7 +650,7 @@ fn applydp_operations( Operations::Regex_Replace => { // safety: we set REGEX_REPLACE in validate_operations() let regexreplace = REGEX_REPLACE.get().unwrap(); - *cell = regexreplace.replace_all(cell, replacement).to_string(); + *cell = regexreplace.replace_all(cell, replacement).into_owned(); }, Operations::Round => { if let Ok(num) = cell.parse::() {