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

StringBuilder.toString() and StringBuffer.toString() optimization

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • 7
    • 7
    • hotspot
    • generic, sparc
    • generic, solaris_9

      The optimization is to have the (JIT) compiler identify StringBuilder and StringBuffer usages where a StringBuilder or StringBuffer is allocated, things are appended to the StringBuilder or StringBuffer and StringBuilder.toString() or StringBuffer.toString() is called. Usages where the StringBuilder or StringBuffer does not escape or becomes dead, the char[] allocated by the StringBuilder or StringBuffer could be assigned to the String returned by the toString() method of StringBuilder or StringBuffer instead of allocating an additional char[] in a new String and copying the char's from the StringBuilder or StringBuffer's char[] to the String's newly allocated char[].

      The end result is the saving of an unnecessary char[] allocation and a subsequent call to arraycopy.

            kvn Vladimir Kozlov
            kvn Vladimir Kozlov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: