Dimchikkk commented on code in PR #13364:
URL: https://github.com/apache/datafusion/pull/13364#discussion_r1837566463


##########
datafusion/functions/src/regex/regexpcount.rs:
##########
@@ -541,42 +541,45 @@ where
 
                     let pattern =
                         compile_and_cache_regex(regex, flags, &mut 
regex_cache)?;
-                    count_matches(value, &pattern, start)
+                    count_matches(value, pattern, start)
                 })
                 .collect::<Result<Vec<i64>, ArrowError>>()?,
             )))
         }
     }
 }
 
-fn compile_and_cache_regex(
-    regex: &str,
-    flags: Option<&str>,
-    regex_cache: &mut HashMap<String, Regex>,
-) -> Result<Regex, ArrowError> {
-    match regex_cache.entry(regex.to_string()) {
-        Entry::Vacant(entry) => {
-            let compiled = compile_regex(regex, flags)?;
-            entry.insert(compiled.clone());
-            Ok(compiled)
-        }
-        Entry::Occupied(entry) => Ok(entry.get().to_owned()),
+fn compile_and_cache_regex<'a>(
+    regex: &'a str,
+    flags: Option<&'a str>,
+    regex_cache: &'a mut HashMap<String, Regex>,

Review Comment:
   Good point. I tried to adjust it but then the keys should live at least as 
long as HashMap, so I couldn't make it compile. regexp_replace also uses String 
as HashMap keys so I think it's fine. However, I removed one unnecessary clone 
by changing signature of compile_regex func. 



-- 
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]

Reply via email to