Pass StringBuilder's buffer directly to String

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Duplicate
    • Priority: P3
    • None
    • Affects Version/s: 6
    • Component/s: core-libs
    • x86
    • windows_xp

      A DESCRIPTION OF THE REQUEST :
      Consider the example code. StringBuilder is not going to escape. A String is going to be created at the end. We can eliminate a memory allocation and buffer copy by simply having the String object reference the char[] in StringBuilder. Since the StringBuilder can't be used any more, the optimized code can simply have String reference the char[] in StringBuilder.

      JUSTIFICATION :
      Consider the example code. StringBuilder is not going to escape. A String is going to be created at the end. We can eliminate a memory allocation and buffer copy by simply having the String object reference the char[] in StringBuilder.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The char[] referenced in StringBuilder be passed to String.
      ACTUAL -
      A separate char[] is created for String and populated with the contents of StringBuilder's char[].

      ---------- BEGIN SOURCE ----------


      StringBuilder result;

      result = new StringBuilder();

      result.append("hello");
      ...

      return(result.toString());
      ---------- END SOURCE ----------

            Assignee:
            Unassigned
            Reporter:
            Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: