You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by zh...@apache.org on 2022/05/23 07:08:14 UTC

[dolphinscheduler] branch 3.0.0-beta-prepare updated: [refactor][perf] cache compiled regex pattern (#10099)

This is an automated email from the ASF dual-hosted git repository.

zhongjiajie pushed a commit to branch 3.0.0-beta-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/3.0.0-beta-prepare by this push:
     new 69a76e8658 [refactor][perf] cache compiled regex pattern (#10099)
69a76e8658 is described below

commit 69a76e8658d70bab70c1dbbbc96771f68fdc210e
Author: youzipi <bl...@qq.com>
AuthorDate: Sat May 21 10:36:42 2022 +0800

    [refactor][perf] cache compiled regex pattern (#10099)
    
    
    (cherry picked from commit 5161df04d75dce3dec6cc4114c38d3414ea93af8)
---
 .../apache/dolphinscheduler/common/utils/ParameterUtils.java  | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ParameterUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ParameterUtils.java
index a1241022a8..dba207a6cf 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ParameterUtils.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ParameterUtils.java
@@ -40,9 +40,8 @@ import java.util.regex.Pattern;
  * parameter parse utils
  */
 public class ParameterUtils {
-    private static final String DATE_PARSE_PATTERN = "\\$\\[([^\\$\\]]+)]";
-
-    private static final String DATE_START_PATTERN = "^[0-9]";
+    private static final Pattern DATE_PARSE_PATTERN = Pattern.compile("\\$\\[([^\\$\\]]+)]");
+    private static final Pattern DATE_START_PATTERN = Pattern.compile("^[0-9]");
 
     private ParameterUtils() {
         throw new UnsupportedOperationException("Construct ParameterUtils");
@@ -165,15 +164,15 @@ public class ParameterUtils {
         if (templateStr == null) {
             return null;
         }
-        Pattern pattern = Pattern.compile(DATE_PARSE_PATTERN);
+
 
         StringBuffer newValue = new StringBuffer(templateStr.length());
 
-        Matcher matcher = pattern.matcher(templateStr);
+        Matcher matcher = DATE_PARSE_PATTERN.matcher(templateStr);
 
         while (matcher.find()) {
             String key = matcher.group(1);
-            if (Pattern.matches(DATE_START_PATTERN, key)) {
+            if (DATE_START_PATTERN.matcher(key).matches()) {
                 continue;
             }
             String value = TimePlaceholderUtils.getPlaceHolderTime(key, date);