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.test/tst | |
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.test/tst')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ReflogCommandTest.java | 6 | ||||
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ReflogCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ReflogCommandTest.java index b07c7033f5..8922837139 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ReflogCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ReflogCommandTest.java @@ -89,7 +89,7 @@ public class ReflogCommandTest extends RepositoryTestCase { Collection<ReflogEntry> reflog = git.reflog().call(); assertNotNull(reflog); assertEquals(3, reflog.size()); - ReflogEntry[] reflogs = reflog.toArray(new ReflogEntry[reflog.size()]); + ReflogEntry[] reflogs = reflog.toArray(new ReflogEntry[0]); assertEquals(reflogs[2].getComment(), "commit (initial): Initial commit"); assertEquals(reflogs[2].getNewId(), commit1.getId()); @@ -114,7 +114,7 @@ public class ReflogCommandTest extends RepositoryTestCase { .setRef(Constants.R_HEADS + "b1").call(); assertNotNull(reflog); assertEquals(2, reflog.size()); - ReflogEntry[] reflogs = reflog.toArray(new ReflogEntry[reflog.size()]); + ReflogEntry[] reflogs = reflog.toArray(new ReflogEntry[0]); assertEquals(reflogs[0].getComment(), "commit: Removed file"); assertEquals(reflogs[0].getNewId(), commit2.getId()); assertEquals(reflogs[0].getOldId(), commit1.getId()); @@ -136,7 +136,7 @@ public class ReflogCommandTest extends RepositoryTestCase { Collection<ReflogEntry> reflog = git.reflog().call(); assertNotNull(reflog); assertEquals(4, reflog.size()); - ReflogEntry[] reflogs = reflog.toArray(new ReflogEntry[reflog.size()]); + ReflogEntry[] reflogs = reflog.toArray(new ReflogEntry[0]); assertEquals(reflogs[3].getComment(), "commit (initial): Initial commit"); assertEquals(reflogs[3].getNewId(), commit1.getId()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java index 71a2f327c8..15d03d38e7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java @@ -231,8 +231,8 @@ public class PathFilterGroupTest { } } - String[] e = expect.toArray(new String[expect.size()]); - String[] a = actual.toArray(new String[actual.size()]); + String[] e = expect.toArray(new String[0]); + String[] a = actual.toArray(new String[0]); Arrays.sort(e); Arrays.sort(a); assertArrayEquals(e, a); |