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

use StringJoiner in sjavac option handling

XMLWordPrintable

    • b106
    • Not verified

      From Liam at Google:

      Some benchmarking showed that sjavac's option handling is spending a lot of time on string concatenation. Any interest in taking this trivial fix?

      # HG changeset patch
      # User Liam Miller-Cushon <cushon at google dot com>
      # Date 1454615087 28800
      # Thu Feb 04 11:44:47 2016 -0800
      # Node ID dea4ee331c161ffda376b1a91f84c4e905f0d0fe
      # Parent 873c5cde4f08f6fffe02cd1f2877111783797be7
      Use StringJoiner in sjavac options handling

      diff -r 873c5cde4f08 -r dea4ee331c16 src/jdk.compiler/share/classes/com/sun/tools/sjavac/options/Options.java
      --- a/src/jdk.compiler/share/classes/com/sun/tools/sjavac/options/Options.java Tue Feb 02 16:11:09 2016 -0800
      +++ b/src/jdk.compiler/share/classes/com/sun/tools/sjavac/options/Options.java Thu Feb 04 11:44:47 2016 -0800
      @@ -33,6 +33,7 @@
       import java.util.List;
       import java.util.Map;
       import java.util.Set;
      +import java.util.StringJoiner;
       import java.util.HashSet;
       
       import com.sun.tools.sjavac.Transformer;
      @@ -225,10 +226,7 @@
                   }
       
                   String getResult() {
      - String result = "";
      - for (String s : args)
      - result += s + " ";
      - return result.trim();
      + return String.join(" ", args);
                   }
       
                   public void addAll(Collection<String> toAdd) {
      @@ -337,10 +335,11 @@
           // Helper method to join a list of source locations separated by
           // File.pathSeparator
           private static String concatenateSourceLocations(List<SourceLocation> locs) {
      - String s = "";
      - for (SourceLocation loc : locs)
      - s += (s.isEmpty() ? "" : java.io.File.pathSeparator) + loc.getPath();
      - return s;
      + StringJoiner joiner = new StringJoiner(java.io.File.pathSeparator);
      + for (SourceLocation loc : locs) {
      + joiner.add(loc.getPath().toString());
      + }
      + return joiner.toString();
           }
       
           // OptionHelper that records the traversed options in this Options instance.

            alundblad Andreas Lundblad (Inactive)
            jjg Jonathan Gibbons
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: