Use StringBuilder in java.util.Matcher
Xueming Shen
xueming.shen at oracle.com
Thu Jul 29 12:33:17 PDT 2010
There is a webrev from Martin at google to add the support of using
StringBuilder for better
performance (I need go back to my old Sun mailbox to dig it out) and
there is the RFE
5066679: java.util.regex.Matcher should make more use of Appendable
which might provide a better approach, and an incomplete webrev can be
found at
http://cr.openjdk.java.net/~sherman/regex_replace/webrev
The only issue left is how to appropriately deal with a possible IOE
from Appendable
interface.
-Sherman
David Dabbs wrote:
> Changing the signature to AbstractStringBuilder would make it compatible
> with both.
>
>
> abstract class: AbstractStringBuilder [javadoc | source]
>
> java.lang.Object
> java.lang.AbstractStringBuilder
>
> Direct Known Subclasses:
> StringBuilder, StringBuffer
>
> since: 1.5
>
>
>
>
> Best,
>
> David
>
>
> -----Original Message-----
> From: nio-dev-bounces at openjdk.java.net
> [mailto:nio-dev-bounces at openjdk.java.net] On Behalf Of ibrahim CHAEHOI
> Sent: Thursday, July 29, 2010 1:50 PM
> To: nio-dev at openjdk.java.net
> Subject: Use StringBuilder in java.util.Matcher
>
> Hi all,
>
> I'm not sure if it's the right mailing list to post this question,
> if it's not the case please let me know what is the proper mailing
> list to post this question.
>
> I just would like to know if there is any reason why the
> appendReplacement method in java.util.Matcher API is only using
> StringBuffer.
> Would it be possible to add 2 new methods appendReplacement and
> appendTail which use a StringBuilder instead of a StringBuffer?
>
> public Matcher appendReplacement(StringBuilder sb, String replacement);
>
> public StringBuilder appendTail(StringBuilder sb, String replacement);
>
> The StringBuilder was introduce in Java 5 as an optimized version of
> the StringBuffer, when the synchronization is not necessary,
> and I'm a bit surprised that the Matcher API doesn't provide a method
> which use a StringBuilder.
>
> Cheers,
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 9.0.851 / Virus Database: 271.1.1/3035 - Release Date: 07/29/10
> 01:34:00
>
>
More information about the jdk6-dev
mailing list