Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-990

Avoid String allocation in StrBuilder.append(CharSequence)

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.3.1
    • 3.4
    • lang.text.*

    Description

      StrBuilder.append(CharSequence) and StrBuilder.append(CharSequence, int, int) can be optimized for the case when CharBuffer is passed. Current implementation calls toString() method that allocates a new String. In case when CharBuffer.hasArray() returns true the buffer-backing char array can be accessed directly to copy chars from it.

      Also an instanceOf StrBuilder check can be added to StrBuilder.append(CharSequence) and StrBuilder.append(CharSequence, int, int) to avoid toString() in that case too (StrBuilder can be passed as CharSequence in some cases).

      Attachments

        1. LANG-990.patch
          4 kB
          Mikhail Mazursky
        2. LANG-990-v2.patch
          4 kB
          Mikhail Mazursky
        3. LANG-990-v3.patch
          5 kB
          Mikhail Mazursky

        Activity

          People

            britter Benedikt Ritter
            ash2k Mikhail Mazursky
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: