From ad6c010beba81c5bf35b5ff97db2ef9b335efd55 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Fri, 7 Nov 2014 16:09:16 +0300 Subject: [PATCH] [git] IDEA-132552 Use THashSet instead of HashSet for VcsRefs to save some memory --- .../src/git4idea/log/GitLogProvider.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/plugins/git4idea/src/git4idea/log/GitLogProvider.java b/plugins/git4idea/src/git4idea/log/GitLogProvider.java index 0b50a55c5e1a..8d956cfe801e 100644 --- a/plugins/git4idea/src/git4idea/log/GitLogProvider.java +++ b/plugins/git4idea/src/git4idea/log/GitLogProvider.java @@ -39,6 +39,7 @@ import git4idea.history.GitHistoryUtils; import git4idea.repo.GitRepository; import git4idea.repo.GitRepositoryChangeListener; import git4idea.repo.GitRepositoryManager; +import gnu.trove.THashSet; import gnu.trove.TObjectHashingStrategy; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -121,10 +122,10 @@ public class GitLogProvider implements VcsLogProvider { currentTagNames = readCurrentTagNames(root); addOldStillExistingTags(allRefs, currentTagNames, rex.getPreviousRefs()); - allDetails = ContainerUtil.newHashSet(data.getCommits()); + allDetails = newHashSet(data.getCommits()); - Set previousTags = new HashSet(ContainerUtil.mapNotNull(rex.getPreviousRefs(), GET_TAG_NAME)); - Set safeTags = new HashSet(ContainerUtil.mapNotNull(safeRefs, GET_TAG_NAME)); + Set previousTags = newHashSet(ContainerUtil.mapNotNull(rex.getPreviousRefs(), GET_TAG_NAME)); + Set safeTags = newHashSet(ContainerUtil.mapNotNull(safeRefs, GET_TAG_NAME)); Set newUnmatchedTags = remove(currentTagNames, previousTags, safeTags); if (!newUnmatchedTags.isEmpty()) { @@ -263,14 +264,14 @@ public class GitLogProvider implements VcsLogProvider { @NotNull private Set readCurrentTagNames(@NotNull VirtualFile root) throws VcsException { - Set tags = ContainerUtil.newHashSet(); + Set tags = newHashSet(); GitTag.listAsStrings(myProject, root, tags, null); return tags; } @NotNull private static Set remove(@NotNull Set original, @NotNull Set... toRemove) { - Set result = ContainerUtil.newHashSet(original); + Set result = newHashSet(original); for (Set set : toRemove) { result.removeAll(set); } @@ -305,8 +306,8 @@ public class GitLogProvider implements VcsLogProvider { parameters.add("--sparse"); final GitBekParentFixer parentFixer = GitBekParentFixer.prepare(root, this); - Set userRegistry = ContainerUtil.newHashSet(); - Set refs = ContainerUtil.newHashSet(); + Set userRegistry = newHashSet(); + Set refs = newHashSet(); GitHistoryUtils.readCommits(myProject, root, parameters, new CollectConsumer(userRegistry), new CollectConsumer(refs), new Consumer() { @Override @@ -339,7 +340,7 @@ public class GitLogProvider implements VcsLogProvider { VirtualFile root = repository.getRoot(); Collection localBranches = repository.getBranches().getLocalBranches(); Collection remoteBranches = repository.getBranches().getRemoteBranches(); - Set refs = new HashSet(localBranches.size() + remoteBranches.size()); + Set refs = new THashSet(localBranches.size() + remoteBranches.size()); for (GitLocalBranch localBranch : localBranches) { refs.add( myVcsObjectsFactory.createRef(HashImpl.build(localBranch.getHash()), localBranch.getName(), GitRefManager.LOCAL_BRANCH, root)); @@ -495,4 +496,15 @@ public class GitLogProvider implements VcsLogProvider { } return true; } + + @NotNull + private static Set newHashSet() { + return new THashSet(); + } + + @NotNull + private static Set newHashSet(@NotNull Collection initialCollection) { + return new THashSet(initialCollection); + } + } \ No newline at end of file