viirya commented on code in PR #5235:
URL: https://github.com/apache/arrow-rs/pull/5235#discussion_r1435384693
##########
arrow-string/src/regexp.rs:
##########
@@ -216,15 +215,14 @@ pub fn regexp_match<OffsetSize: OffsetSizeTrait>(
(Some(value), Some(pattern)) => {
let existing_pattern = patterns.get(&pattern);
let re = match existing_pattern {
- Some(re) => re.clone(),
+ Some(re) => re,
None => {
let re = Regex::new(pattern.as_str()).map_err(|e| {
ArrowError::ComputeError(format!(
"Regular expression did not compile: {e:?}"
))
})?;
- patterns.insert(pattern, re.clone());
- re
+ patterns.entry(pattern).or_insert(re)
Review Comment:
Oh, the branch to eliminate is the one inside `or_insert`? Do you mean
something like:
```rust
let entry = patterns.entry(pattern.clone());
let re = match entry {
Entry::Occupied(entry) => entry.into_mut(),
Entry::Vacant(entry) => {
let re = Regex::new(pattern.as_str()).map_err(|e| {
ArrowError::ComputeError(format!(
"Regular expression did not compile: {e:?}"
))
})?;
entry.insert(re)
}
};
```
Hmm, it actually gets regression a little. 🤔
```
regexp time: [7.6891 ms 7.7210 ms 7.7511 ms]
change: [+14.792% +15.570% +16.321%] (p = 0.00 <
0.05)
Performance has regressed.
```
--
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]