RFR: Use StringJoiner in sjavac options handling
Andreas Lundblad
andreas.lundblad at oracle.com
Mon Feb 8 21:43:50 UTC 2016
On Thu, Feb 04, 2016 at 11:57:56AM -0800, Liam Miller-Cushon wrote:
> Some benchmarking showed that sjavac's option handling is spending a lot of
> time on string concatenation. Any interest in taking this trivial fix?
Sorry for late reply. Change looks great.
Will you push it or should I?
-- Andreas
> # 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.
More information about the compiler-dev
mailing list