[PATCH] minor regex cleanup: use switch for enum

Isaac Levy isaac.r.levy at gmail.com
Mon Apr 23 20:49:59 UTC 2018


Thanks. Another small perf patch below -- maybe we can combine. Avoids a
StringBuilder allocation:

--- a/src/java.base/share/classes/java/util/regex/Matcher.java
+++ b/src/java.base/share/classes/java/util/regex/Matcher.java
@@ -993,13 +993,11 @@
    public Matcher appendReplacement(StringBuilder sb, String replacement) {
         // If no match, return error
         if (first < 0)
             throw new IllegalStateException("No match available");
-        StringBuilder result = new StringBuilder();
-        appendExpandedReplacement(replacement, result);
         // Append the intervening text
         sb.append(text, lastAppendPosition, first);
         // Append the match substitution
+        appendExpandedReplacement(replacement, sb);
-        sb.append(result);


On Mon, Apr 23, 2018 at 4:31 PM, Xueming Shen <xueming.shen at oracle.com>
wrote:
> this looks fine.
>
> -sherman


More information about the core-libs-dev mailing list