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

(str) Adapt StringJoiner for Compact Strings

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P3
    • 17
    • 9
    • core-libs
    • b14

    Description

      Current StringJoiner code tries to build the char[] storage by itself:

          @Override
          public String toString() {
              ...
              final String delimiter = this.delimiter;
              final char[] chars = new char[len + addLen];
              int k = getChars(prefix, chars, 0);
              if (size > 0) {
                  k += getChars(elts[0], chars, k);
                  for (int i = 1; i < size; i++) {
                      k += getChars(delimiter, chars, k);
                      k += getChars(elts[i], chars, k);
                  }
              }
              k += getChars(suffix, chars, k);
              return jla.newStringUnsafe(chars);
          }

      This is seems to be a performance optimization, but it clashes with Compact Strings which now have to re-compress the resulting char[] array into byte[]. We may want to extend this mechanism by figuring out the coders for arguments, and creating byte[] with appropriate coder, then using a private String constructor that does not re-compress.

      Attachments

        Issue Links

          Activity

            People

              redestad Claes Redestad
              shade Aleksey Shipilev
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: