Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Keppler2019-07-17 14:16:14 -0400
committerMichael Keppler2019-10-01 02:06:19 -0400
commit4ca90b89a342a6b2422c252dd23d970634b54680 (patch)
treec79a0007bab457d319fa4ad728b333f98eb4b666
parent7363c8dd70987c28137ded74509ca4289d036ee2 (diff)
downloadegit-4ca90b89a342a6b2422c252dd23d970634b54680.tar.gz
egit-4ca90b89a342a6b2422c252dd23d970634b54680.tar.xz
egit-4ca90b89a342a6b2422c252dd23d970634b54680.zip
Simplify collection.toArray() calls
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/ Regex used for search: (?s)\Q.toArray(\E\s*new\s+\w+\Q[\E(?!0) Change-Id: Ifa2f498d97209a01cdb219c79ced20660af91886 Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/PullOperation.java2
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java3
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitSubscriberMergeContext.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIUtils.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/RepositoryLocationContentProvider.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffRegionFormatter.java4
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/RepositoryCommit.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitCombo.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FileDiff.java4
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FindResults.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/SynchronizePreferencePage.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/pull/PullOperationUI.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseResultDialog.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/SharingWizard.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitSynchronizeWizard.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelRepository.java2
18 files changed, 22 insertions, 34 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/PullOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/PullOperation.java
index 874200856..2b6554723 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/PullOperation.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/PullOperation.java
@@ -140,7 +140,7 @@ public class PullOperation implements IEGitOperation {
public PullOperation(Set<Repository> repositories, int timeout) {
this.timeout = timeout;
this.repositories = repositories
- .toArray(new Repository[repositories.size()]);
+ .toArray(new Repository[0]);
this.configs = Collections.emptyMap();
this.results = new LinkedHashMap<>();
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java
index 425ab6985..671a24cc2 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java
@@ -202,8 +202,7 @@ public class GitProjectData {
*/
private static synchronized RepositoryMappingChangeListener[] getRepositoryChangeListeners() {
return repositoryChangeListeners
- .toArray(new RepositoryMappingChangeListener[repositoryChangeListeners
- .size()]);
+ .toArray(new RepositoryMappingChangeListener[0]);
}
/**
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitSubscriberMergeContext.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitSubscriberMergeContext.java
index 943b0da6b..fa481b699 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitSubscriberMergeContext.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitSubscriberMergeContext.java
@@ -179,8 +179,7 @@ public class GitSubscriberMergeContext extends SubscriberMergeContext {
}
private void refreshResources(Collection<IFile> resources) {
- IResource[] files = resources.toArray(new IResource[resources
- .size()]);
+ IResource[] files = resources.toArray(new IResource[0]);
try {
subscriber.refresh(files, IResource.DEPTH_ONE,
new NullProgressMonitor());
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIUtils.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIUtils.java
index 89922c017..0cdd39750 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIUtils.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIUtils.java
@@ -445,8 +445,7 @@ public class UIUtils {
resultList.add(propsal);
}
}
- return resultList.toArray(new IContentProposal[resultList
- .size()]);
+ return resultList.toArray(new IContentProposal[0]);
}
};
@@ -597,8 +596,7 @@ public class UIUtils {
resultList.add(proposal);
}
}
- return resultList.toArray(new IContentProposal[resultList
- .size()]);
+ return resultList.toArray(new IContentProposal[0]);
}
};
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java
index 78c1f11fb..166b5c68d 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java
@@ -151,8 +151,7 @@ public class CommitActionHandler extends RepositoryActionHandler {
result[0] = new IndexDiffData(
CommitUI.getIndexDiff(repository,
projects.toArray(
- new IProject[projects
- .size()]),
+ new IProject[0]),
monitor));
} catch (IOException e) {
throw new InvocationTargetException(e);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/RepositoryLocationContentProvider.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/RepositoryLocationContentProvider.java
index 17fbdaf0f..f589afbeb 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/RepositoryLocationContentProvider.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/RepositoryLocationContentProvider.java
@@ -57,8 +57,7 @@ class RepositoryLocationContentProvider implements ITreeContentProvider {
@SuppressWarnings("unchecked")
public Object[] getElements(Object inputElement) {
List<CloneSourceProvider> repositoryImports = (List<CloneSourceProvider>) inputElement;
- return repositoryImports.toArray(new CloneSourceProvider[repositoryImports
- .size()]);
+ return repositoryImports.toArray(new CloneSourceProvider[0]);
}
@Override
@@ -76,8 +75,7 @@ class RepositoryLocationContentProvider implements ITreeContentProvider {
return null;
cacheParents(repositoryImport, repositoryServerInfos);
return repositoryServerInfos
- .toArray(new RepositoryServerInfo[repositoryServerInfos
- .size()]);
+ .toArray(new RepositoryServerInfo[0]);
}
return null;
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffRegionFormatter.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffRegionFormatter.java
index 84a331ac5..0631ed12e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffRegionFormatter.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffRegionFormatter.java
@@ -322,7 +322,7 @@ public class DiffRegionFormatter extends DiffFormatter {
* @return non-null but possibly empty array
*/
public DiffRegion[] getRegions() {
- return this.regions.toArray(new DiffRegion[this.regions.size()]);
+ return this.regions.toArray(new DiffRegion[0]);
}
/**
@@ -332,7 +332,7 @@ public class DiffRegionFormatter extends DiffFormatter {
*/
public FileDiffRegion[] getFileRegions() {
return this.fileRegions
- .toArray(new FileDiffRegion[this.fileRegions.size()]);
+ .toArray(new FileDiffRegion[0]);
}
/**
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java
index fce1d1292..acdb79755 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java
@@ -169,7 +169,7 @@ public class DiffViewer extends HyperlinkSourceViewer {
Assert.isTrue(sourceViewer instanceof DiffViewer);
DiffViewer viewer = (DiffViewer) sourceViewer;
return viewer.tokens.keySet()
- .toArray(new String[viewer.tokens.size()]);
+ .toArray(new String[0]);
}
@Override
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/RepositoryCommit.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/RepositoryCommit.java
index 8cd37fff5..5fd6f5206 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/RepositoryCommit.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/RepositoryCommit.java
@@ -207,8 +207,7 @@ public class RepositoryCommit extends WorkbenchAdapter
if (note != null)
noteList.add(new RepositoryCommitNote(this, ref, note));
}
- notes = noteList.toArray(new RepositoryCommitNote[noteList
- .size()]);
+ notes = noteList.toArray(new RepositoryCommitNote[0]);
} catch (Exception e) {
Activator.logError("Error showing notes", e); //$NON-NLS-1$
notes = new RepositoryCommitNote[0];
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitCombo.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitCombo.java
index a14d3c691..1615b2f96 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitCombo.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitCombo.java
@@ -75,7 +75,7 @@ public class CommitCombo extends Composite {
list.add(makeContentProposal(message));
}
}
- return list.toArray(new IContentProposal[] {});
+ return list.toArray(new IContentProposal[0]);
}
/*
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FileDiff.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FileDiff.java
index 3bbd68d54..0f96fe36d 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FileDiff.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FileDiff.java
@@ -418,7 +418,7 @@ public class FileDiff {
objectIds.add(diffEntry.getOldId().toObjectId());
if (diffEntry.getNewId() != null)
objectIds.add(diffEntry.getNewId().toObjectId());
- return objectIds.toArray(new ObjectId[]{});
+ return objectIds.toArray(new ObjectId[0]);
}
/**
@@ -432,7 +432,7 @@ public class FileDiff {
modes.add(diffEntry.getOldMode());
if (diffEntry.getOldMode() != null)
modes.add(diffEntry.getOldMode());
- return modes.toArray(new FileMode[]{});
+ return modes.toArray(new FileMode[0]);
}
/**
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FindResults.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FindResults.java
index 3b49dfc18..518ccd365 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FindResults.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FindResults.java
@@ -225,7 +225,7 @@ public class FindResults {
private Integer[] getkeysArray() {
if (keysArray == null) {
keysArray = matchesMap.keySet().toArray(
- new Integer[matchesMap.size()]);
+ new Integer[0]);
}
return keysArray;
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/SynchronizePreferencePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/SynchronizePreferencePage.java
index e0e3a7ab6..3816d7b20 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/SynchronizePreferencePage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/SynchronizePreferencePage.java
@@ -114,7 +114,7 @@ public class SynchronizePreferencePage extends FieldEditorPreferencePage
strategies.add(new String[] { strategy.getLabel(),
strategy.getName() });
}
- return strategies.toArray(new String[strategies.size()][2]);
+ return strategies.toArray(new String[0][0]);
}
private ScopedPreferenceStore getCorePreferenceStore() {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/pull/PullOperationUI.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/pull/PullOperationUI.java
index 6bd1de6cf..506bfc406 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/pull/PullOperationUI.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/pull/PullOperationUI.java
@@ -80,8 +80,7 @@ public class PullOperationUI extends JobChangeAdapter {
* @param repositories
*/
public PullOperationUI(Set<Repository> repositories) {
- this.repositories = repositories.toArray(new Repository[repositories
- .size()]);
+ this.repositories = repositories.toArray(new Repository[0]);
int timeout = Activator.getDefault().getPreferenceStore().getInt(
UIPreferences.REMOTE_CONNECTION_TIMEOUT);
pullOperation = new PullOperation(repositories, timeout);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseResultDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseResultDialog.java
index 555899bfb..94726e8dd 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseResultDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseResultDialog.java
@@ -569,8 +569,7 @@ public class RebaseResultDialog extends MessageDialog {
IPath location = repoWorkdirPath.append(repoPath);
locationList.add(location);
}
- IPath[] locations = locationList.toArray(new IPath[locationList
- .size()]);
+ IPath[] locations = locationList.toArray(new IPath[0]);
int mergeMode = Activator.getDefault().getPreferenceStore()
.getInt(UIPreferences.MERGE_MODE);
CompareEditorInput input;
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/SharingWizard.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/SharingWizard.java
index 3fcbbe17d..e2f79026d 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/SharingWizard.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/SharingWizard.java
@@ -207,8 +207,7 @@ public class SharingWizard extends Wizard implements IConfigurationWizard,
@Override
public void run() {
activePage.closeEditors(
- editorRefsToClose.toArray(
- new IEditorReference[editorRefsToClose.size()]),
+ editorRefsToClose.toArray(new IEditorReference[0]),
true);
}
});
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitSynchronizeWizard.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitSynchronizeWizard.java
index 856b1a6a7..d386626de 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitSynchronizeWizard.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitSynchronizeWizard.java
@@ -83,8 +83,7 @@ public class GitSynchronizeWizard extends Wizard {
Set<IProject> selectedProjects
= page.getSelectedProjects();
GitModelSynchronize.launch(gsdSet, selectedProjects
- .toArray(new IResource[selectedProjects
- .size()]));
+ .toArray(new IResource[0]));
return true;
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelRepository.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelRepository.java
index 1f27a5b05..801aa1052 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelRepository.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelRepository.java
@@ -90,7 +90,7 @@ public class GitModelRepository extends GitModelObjectContainer implements HasPr
@Override
public IProject[] getProjects() {
- return gsd.getProjects().toArray(new IProject[gsd.getProjects().size()]);
+ return gsd.getProjects().toArray(new IProject[0]);
}
@Override

Back to the top