JDK-6893628 : Add support for StringBuilder to java.util.regex.Matcher
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util.regex
  • Affected Version: 6u10
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2009-10-21
  • Updated: 2011-02-16
  • Resolved: 2010-11-19
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
There appears to be an unfortunate JDK1.4 historical artifact of using StringBuffer in the method signatures of appendReplacement and appendTail in the  java.util.regex.Matcher class.  Adding alternate methods that use java.lang.Appendable would allow for a wider choice of classes to be used with Matcher. Updating the internal use of StringBuffer to StringBuilder within Matcher itself would also increase its performance.

JUSTIFICATION :
The slow performance of StringBuffer is well known. JDK 1.5 introduced StringBuilder as a drop in replacement. At that time the interface java.lang.Appendable was introduced. Using Appendable is in the method signature as well as using StringBuilder within the replaceFirst, replaceAll and appendReplacment methods should dramatically increase the performance of Matcher.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Same behavior with better performance and increased flexibility.
ACTUAL -
Same behavior with slow performance.

Comments
EVALUATION We are considering to add support for "Appendable". See#5066679
19-11-2010