You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by GitBox <gi...@apache.org> on 2021/09/23 05:14:12 UTC

[GitHub] [struts] lukaszlenart commented on a change in pull request #497: [WW-5073] - simplify AbstractMatcher convertParam

lukaszlenart commented on a change in pull request #497:
URL: https://github.com/apache/struts/pull/497#discussion_r714475902



##########
File path: core/src/main/java/com/opensymphony/xwork2/config/impl/AbstractMatcher.java
##########
@@ -204,31 +211,22 @@ public E match(String potentialMatch) {
      * @param vars A Map of wildcard-matched strings
      * @return The new value
      */
-    protected String convertParam(String val, Map<String, String> vars) {
-        if (val == null) {
-            return null;
-        } 
-        
-        int len = val.length();
-        StringBuilder ret = new StringBuilder();
-        char c;
-        String varVal;
-        for (int x=0; x<len; x++) {
-            c = val.charAt(x);
-            if (x < len - 2 && 
-                    c == '{' && '}' == val.charAt(x+2)) {
-                varVal = vars.get(String.valueOf(val.charAt(x + 1)));
-                if (varVal != null) {
-                    ret.append(varVal);
-                } 
-                x += 2;
-            } else {
-                ret.append(c);
-            }
-        }
-        
-        return ret.toString();
-    }
+	protected String convertParam(String val, Map<String, String> vars) {
+		if (val == null) {
+			return null;
+		}
+
+		Pattern wildcardPattern = Pattern.compile("\\{(.)\\}");

Review comment:
       Just a small optimisation, could you move this pattern compilation into a field? Right now each time the `convertParam` is called, the same pattern is compiled over and over.




-- 
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: issues-unsubscribe@struts.apache.org

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