Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Keppler2018-08-06 12:11:26 +0000
committerJonathan Nieder2018-08-23 05:34:39 +0000
commit2fc00af44e5658cf34200ad20d777a75333a0564 (patch)
tree4176d6c478946dee29d54fac9d6eb2f91bdbb613 /org.eclipse.jgit.pgm.test
parent7058493fea6992c914a200b64f48b0b61f192ac0 (diff)
downloadjgit-2fc00af44e5658cf34200ad20d777a75333a0564.tar.gz
jgit-2fc00af44e5658cf34200ad20d777a75333a0564.tar.xz
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.test')
-rw-r--r--org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java2
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java12
2 files changed, 7 insertions, 7 deletions
diff --git a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java
index 44ad79defc..81875f11bc 100644
--- a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java
+++ b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java
@@ -230,7 +230,7 @@ public class CLIGitCommand extends Main {
}
if (r.length() > 0)
list.add(r.toString());
- return list.toArray(new String[list.size()]);
+ return list.toArray(new String[0]);
}
public static class Result {
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java
index afeb5ef6e4..ecc00d37f5 100644
--- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java
@@ -544,7 +544,7 @@ public class ArchiveTest extends CLIRepositoryTestCase {
byte[] result = CLIGitCommand.executeRaw(
"git archive --format=zip HEAD", db).outBytes();
- assertArrayEquals(l.toArray(new String[l.size()]),
+ assertArrayEquals(l.toArray(new String[0]),
listZipEntries(result));
}
@@ -564,7 +564,7 @@ public class ArchiveTest extends CLIRepositoryTestCase {
byte[] result = CLIGitCommand.executeRaw(
"git archive --format=tar HEAD", db).outBytes();
- assertArrayEquals(l.toArray(new String[l.size()]),
+ assertArrayEquals(l.toArray(new String[0]),
listTarEntries(result));
}
@@ -697,7 +697,7 @@ public class ArchiveTest extends CLIRepositoryTestCase {
while ((e = in.getNextEntry()) != null)
l.add(e.getName());
}
- return l.toArray(new String[l.size()]);
+ return l.toArray(new String[0]);
}
private static Future<Object> writeAsync(OutputStream stream, byte[] data) {
@@ -730,7 +730,7 @@ public class ArchiveTest extends CLIRepositoryTestCase {
while ((line = reader.readLine()) != null)
l.add(line);
- return l.toArray(new String[l.size()]);
+ return l.toArray(new String[0]);
} finally {
writing.get();
proc.destroy();
@@ -754,7 +754,7 @@ public class ArchiveTest extends CLIRepositoryTestCase {
String line;
while ((line = reader.readLine()) != null)
l.add(line);
- return l.toArray(new String[l.size()]);
+ return l.toArray(new String[0]);
}
// not found
@@ -774,7 +774,7 @@ public class ArchiveTest extends CLIRepositoryTestCase {
while ((line = reader.readLine()) != null)
l.add(line);
- return l.toArray(new String[l.size()]);
+ return l.toArray(new String[0]);
} finally {
writing.get();
proc.destroy();

Back to the top