From 2ac6376a0ae0bd77978113269398a274b3f43578 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Thu, 5 Dec 2024 10:42:55 +0100 Subject: [PATCH] Use String::len and str::len directly The `len()` returns length in bytes, so doing `as_bytes().len()` is redundant. This will become a clippy warning in the future. --- datafusion/functions/src/string/common.rs | 4 ++-- datafusion/functions/src/unicode/strpos.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/datafusion/functions/src/string/common.rs b/datafusion/functions/src/string/common.rs index 0d1f90eb22b94..6e5f767013d4c 100644 --- a/datafusion/functions/src/string/common.rs +++ b/datafusion/functions/src/string/common.rs @@ -61,7 +61,7 @@ pub(crate) fn general_trim( str::trim_start_matches::<&[char]>(input, pattern.as_ref()); // `ltrimmed_str` is actually `input`[start_offset..], // so `start_offset` = len(`input`) - len(`ltrimmed_str`) - let start_offset = input.as_bytes().len() - ltrimmed_str.as_bytes().len(); + let start_offset = input.len() - ltrimmed_str.len(); (ltrimmed_str, start_offset as u32) }, @@ -78,7 +78,7 @@ pub(crate) fn general_trim( str::trim_start_matches::<&[char]>(input, pattern.as_ref()); // `btrimmed_str` can be got by rtrim(ltrim(`input`)), // so its `start_offset` should be same as ltrim situation above - let start_offset = input.as_bytes().len() - ltrimmed_str.as_bytes().len(); + let start_offset = input.len() - ltrimmed_str.len(); let btrimmed_str = str::trim_end_matches::<&[char]>(ltrimmed_str, pattern.as_ref()); diff --git a/datafusion/functions/src/unicode/strpos.rs b/datafusion/functions/src/unicode/strpos.rs index 1917cd7291cc2..5d1986e44c92a 100644 --- a/datafusion/functions/src/unicode/strpos.rs +++ b/datafusion/functions/src/unicode/strpos.rs @@ -173,13 +173,13 @@ where // the sub vector in the main vector. This is faster than string.find() method. if ascii_only { // If the substring is empty, the result is 1. - if substring.as_bytes().is_empty() { + if substring.is_empty() { T::Native::from_usize(1) } else { T::Native::from_usize( string .as_bytes() - .windows(substring.as_bytes().len()) + .windows(substring.len()) .position(|w| w == substring.as_bytes()) .map(|x| x + 1) .unwrap_or(0),