viirya commented on code in PR #5235:
URL: https://github.com/apache/arrow-rs/pull/5235#discussion_r1435418803


##########
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:
   `clone`? You mean `let entry = patterns.entry(pattern.clone());`?  It cannot 
be removed.
   
   ```
   216 |                 (Some(value), Some(pattern)) => {
       |                                    ------- move occurs because 
`pattern` has type `String`, which does not implement the `Copy` trait
   217 |                     let entry = patterns.entry(pattern);
       |                                                ------- value moved here
   ...
   221 |                             let re = 
Regex::new(pattern.as_str()).map_err(|e| {
       |                                                 ^^^^^^^ value borrowed 
here after move
       |
   help: consider cloning the value if the performance cost is acceptable
       |
   217 |                     let entry = patterns.entry(pattern.clone());
       |                                                       ++++++++
   ```



-- 
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-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to