You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2026/09/30 13:11:05 UTC
Re: [PR] perf: Reuse capture locations in `regexp_match` [arrow-rs]
alamb commented on code in PR #11274:
URL: https://github.com/apache/arrow-rs/pull/11274#discussion_r4144910389
##########
arrow-string/src/regexp.rs:
##########
@@ -332,6 +332,7 @@ fn get_scalar_pattern_flag_utf8view<'a>(
macro_rules! process_regexp_match {
($array:expr, $regex:expr, $list_builder:expr) => {
+ let mut capture_locations = None;
Review Comment:
Can we add a small comment about the use of this (that it is a cache to reuse the locations)?
##########
arrow-string/src/regexp.rs:
##########
@@ -342,19 +343,25 @@ macro_rules! process_regexp_match {
$list_builder.values().append_value("");
$list_builder.append(true);
}
- Some(value) => match $regex.captures(value) {
- Some(caps) => {
- let mut iter = caps.iter();
- if caps.len() > 1 {
- iter.next();
- }
- for m in iter.flatten() {
- $list_builder.values().append_value(m.as_str());
+ Some(value) => {
+ let locations =
+ capture_locations.get_or_insert_with(|| $regex.capture_locations());
+ match $regex.captures_read(locations, value) {
Review Comment:
I think this is the key change -- to use https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_read instead of `captures`
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org