-
Enhancement
-
Resolution: Fixed
-
P4
-
18
-
b16
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
The java.util.regex.Matcher methods appendReplacement(StringBuilder, String) and appendReplacement(StringBuffer, String) both create a new StringBuilder each time they are called. This is pretty wasteful because they are called by replaceAll for each match.
If possible, please reorder the statements to directly write to the result StringBuilder / StringBuffer. If that is not possible, it might be worth investigating whether writing to the result StringBuilder and then using StringBuilder.insert would work and would keep the same performance.
This was originally also mentioned as part ofJDK-6231989, but was apparently not implemented.
The java.util.regex.Matcher methods appendReplacement(StringBuilder, String) and appendReplacement(StringBuffer, String) both create a new StringBuilder each time they are called. This is pretty wasteful because they are called by replaceAll for each match.
If possible, please reorder the statements to directly write to the result StringBuilder / StringBuffer. If that is not possible, it might be worth investigating whether writing to the result StringBuilder and then using StringBuilder.insert would work and would keep the same performance.
This was originally also mentioned as part of
- relates to
-
JDK-6231989 Eliminate unnecessary object creation in Matcher
- Closed