Skip to content

Commit

Permalink
Use String::len and str::len directly
Browse files Browse the repository at this point in the history
The `len()` returns length in bytes, so doing `as_bytes().len()` is
redundant. This will become a clippy warning in the future.
  • Loading branch information
findepi committed Dec 5, 2024
1 parent 4e292c2 commit 2ac6376
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions datafusion/functions/src/string/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub(crate) fn general_trim<T: OffsetSizeTrait>(
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)
},
Expand All @@ -78,7 +78,7 @@ pub(crate) fn general_trim<T: OffsetSizeTrait>(
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());

Expand Down
4 changes: 2 additions & 2 deletions datafusion/functions/src/unicode/strpos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 2ac6376

Please sign in to comment.