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

Optimize String Concat (Unroll) at Compile Time

    Details

    • Type: Enhancement
    • Status: New
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 11, 12
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      The following are equivalent and should be compiled to the same byte code. I see this often in projects, developers use the String concatenation operator "+" inside the body of a StringBuilder/StringBuffer append method. When this is the case, the operator should be converted into an 'append' call on the parent StringBuilder/StringBuffer instead of creating a new StringBuilder/StringBuffer for the intermediate results.

        public static void main(String[] args) {
          StringBuilder sb = new StringBuilder();
          sb.append(args[0] + ' ' + args[1]);
          System.out.println(sb.toString());
        }

        public static void main(String[] args) {
          StringBuilder sb = new StringBuilder();
          sb.append(args[0]);
          sb.append(' ');
          sb.append(args[1]);
          System.out.println(sb.toString());
        }


        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: