RFR: Use StringJoiner in sjavac options handling

Liam Miller-Cushon cushon at google.com
Thu Feb 4 19:57:56 UTC 2016


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.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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20160204/fb74cb44/attachment-0001.html>


More information about the compiler-dev mailing list