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

(str) Adapt StringJoiner for Compact Strings

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 17
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      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

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

                Dates

                Created:
                Updated:
                Resolved: