Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8291598

Matcher.appendReplacement should not create new StringBuilder instances

XMLWordPrintable

    • 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 of JDK-6231989, but was apparently not implemented.


            rgiulietti Raffaello Giulietti
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: