Rich-T-kid commented on code in PR #24153:
URL: https://github.com/apache/datafusion/pull/24153#discussion_r3741721702
##########
datafusion/functions/src/regex/regexpcount.rs:
##########
@@ -565,27 +565,10 @@ fn count_matches(
));
}
- let char_len = value.chars().count();
- let start_index = (start as usize).saturating_sub(1);
-
- if start_index > char_len {
+ let Some(byte_offset) = start_to_byte_offset(value, start) else {
return Ok(0);
- }
-
- // Find the byte offset for the start position (1-based character
index)
- let byte_offset = if start_index == char_len {
- value.len()
- } else {
- value
- .char_indices()
- .nth(start_index)
- .map(|(idx, _)| idx)
- .unwrap_or(value.len())
};
-
- // Use string slicing instead of collecting chars into a new String
- let find_slice = &value[byte_offset..];
- let count = pattern.find_iter(find_slice).count();
Review Comment:
nice 🩸
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]