diff options
author | Michael Keppler <Michael.Keppler@gmx.de> | 2018-08-06 14:11:26 +0200 |
---|---|---|
committer | Jonathan Nieder <jrn@google.com> | 2018-08-23 01:34:39 -0400 |
commit | 2fc00af44e5658cf34200ad20d777a75333a0564 (patch) | |
tree | 4176d6c478946dee29d54fac9d6eb2f91bdbb613 /org.eclipse.jgit.pgm/src | |
parent | 7058493fea6992c914a200b64f48b0b61f192ac0 (diff) | |
download | jgit-2fc00af44e5658cf34200ad20d777a75333a0564.tar.gz jgit-2fc00af44e5658cf34200ad20d777a75333a0564.zip |
refactor: simplify collection.toArray()
On recent VMs, collection.toArray(new T[0]) is faster than
collection.toArray(new T[collection.size()]). Since it is also more
readable, it should now be the preferred way of collection to array
conversion.
https://shipilev.net/blog/2016/arrays-wisdom-ancients/
Change-Id: I80388532fb4b2b0663ee1fe8baa94f5df55c8442
Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
Diffstat (limited to 'org.eclipse.jgit.pgm/src')
5 files changed, 5 insertions, 5 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CommandCatalog.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CommandCatalog.java index 5754d7c44f..2b0e5a717d 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CommandCatalog.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CommandCatalog.java @@ -114,7 +114,7 @@ public class CommandCatalog { } private static CommandRef[] toSortedArray(Collection<CommandRef> c) { - final CommandRef[] r = c.toArray(new CommandRef[c.size()]); + final CommandRef[] r = c.toArray(new CommandRef[0]); Arrays.sort(r, new Comparator<CommandRef>() { @Override public int compare(CommandRef o1, CommandRef o2) { diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java index f9c1cf5d38..f91474859d 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java @@ -73,7 +73,7 @@ class Describe extends TextBuiltin { if (tree != null) cmd.setTarget(tree); cmd.setLong(longDesc); - cmd.setMatch(patterns.toArray(new String[patterns.size()])); + cmd.setMatch(patterns.toArray(new String[0])); String result = null; try { result = cmd.call(); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java index ac53de9767..6fa92d3b0b 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java @@ -285,7 +285,7 @@ public class Main { final TextBuiltin cmd = subcommand; init(cmd); try { - cmd.execute(arguments.toArray(new String[arguments.size()])); + cmd.execute(arguments.toArray(new String[0])); } finally { if (cmd.outw != null) { cmd.outw.flush(); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Remote.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Remote.java index 3308e18f24..63eba15abc 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Remote.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Remote.java @@ -130,7 +130,7 @@ class Remote extends TextBuiltin { fetchArgs.add(name); } - fetch.execute(fetchArgs.toArray(new String[fetchArgs.size()])); + fetch.execute(fetchArgs.toArray(new String[0])); // flush the streams fetch.outw.flush(); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/CmdLineParser.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/CmdLineParser.java index 5cc98ca8ac..b97aa5b7af 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/CmdLineParser.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/CmdLineParser.java @@ -177,7 +177,7 @@ public class CmdLineParser extends org.kohsuke.args4j.CmdLineParser { } try { - super.parseArgument(tmp.toArray(new String[tmp.size()])); + super.parseArgument(tmp.toArray(new String[0])); } catch (Die e) { if (!seenHelp) { throw e; |