mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
memory optimisation: eliminate TIntArrayList slack
This commit is contained in:
@@ -27,10 +27,7 @@ import gnu.trove.TIntArrayList;
|
||||
import gnu.trove.TIntObjectHashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.AbstractCollection;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -38,16 +35,13 @@ public class CompressedRefs {
|
||||
@NotNull private final VcsLogStorage myHashMap;
|
||||
|
||||
// maps each commit id to the list of tag ids on this commit
|
||||
@NotNull private final TIntObjectHashMap<TIntArrayList> myTags;
|
||||
@NotNull private final TIntObjectHashMap<TIntArrayList> myTags = new TIntObjectHashMap<>();
|
||||
// maps each commit id to the list of branches on this commit
|
||||
@NotNull private final TIntObjectHashMap<SmartList<VcsRef>> myBranches;
|
||||
@NotNull private final TIntObjectHashMap<List<VcsRef>> myBranches = new TIntObjectHashMap<>();
|
||||
|
||||
public CompressedRefs(@NotNull Set<VcsRef> refs, @NotNull VcsLogStorage hashMap) {
|
||||
myHashMap = hashMap;
|
||||
|
||||
myTags = new TIntObjectHashMap<>();
|
||||
myBranches = new TIntObjectHashMap<>();
|
||||
|
||||
Ref<VirtualFile> root = new Ref<>();
|
||||
|
||||
refs.forEach(ref -> {
|
||||
@@ -61,12 +55,15 @@ public class CompressedRefs {
|
||||
putRefIndex(myTags, ref, myHashMap);
|
||||
}
|
||||
});
|
||||
|
||||
myTags.forEachValue(list -> {
|
||||
list.trimToSize();
|
||||
return true;
|
||||
});
|
||||
myHashMap.flush();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public SmartList<VcsRef> refsToCommit(int index) {
|
||||
SmartList<VcsRef> refsToCommit(int index) {
|
||||
SmartList<VcsRef> result = new SmartList<>();
|
||||
if (myBranches.containsKey(index)) result.addAll(myBranches.get(index));
|
||||
TIntArrayList tags = myTags.get(index);
|
||||
@@ -80,7 +77,7 @@ public class CompressedRefs {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Stream<VcsRef> streamBranches() {
|
||||
Stream<VcsRef> streamBranches() {
|
||||
return TroveUtil.streamValues(myBranches).flatMap(Collection::stream);
|
||||
}
|
||||
|
||||
@@ -100,6 +97,7 @@ public class CompressedRefs {
|
||||
private final Supplier<Collection<VcsRef>> myLoadedRefs =
|
||||
Suppliers.memoize(() -> CompressedRefs.this.stream().collect(Collectors.toList()));
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<VcsRef> iterator() {
|
||||
return myLoadedRefs.get().iterator();
|
||||
@@ -120,14 +118,14 @@ public class CompressedRefs {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void putRef(@NotNull TIntObjectHashMap<SmartList<VcsRef>> map, @NotNull VcsRef ref, @NotNull VcsLogStorage hashMap) {
|
||||
private static void putRef(@NotNull TIntObjectHashMap<List<VcsRef>> map, @NotNull VcsRef ref, @NotNull VcsLogStorage hashMap) {
|
||||
int index = hashMap.getCommitIndex(ref.getCommitHash(), ref.getRoot());
|
||||
SmartList<VcsRef> list = map.get(index);
|
||||
List<VcsRef> list = map.get(index);
|
||||
if (list == null) map.put(index, list = new SmartList<>());
|
||||
list.add(ref);
|
||||
}
|
||||
|
||||
public static void putRefIndex(@NotNull TIntObjectHashMap<TIntArrayList> map, @NotNull VcsRef ref, @NotNull VcsLogStorage hashMap) {
|
||||
private static void putRefIndex(@NotNull TIntObjectHashMap<TIntArrayList> map, @NotNull VcsRef ref, @NotNull VcsLogStorage hashMap) {
|
||||
int index = hashMap.getCommitIndex(ref.getCommitHash(), ref.getRoot());
|
||||
TIntArrayList list = map.get(index);
|
||||
if (list == null) map.put(index, list = new TIntArrayList());
|
||||
|
||||
Reference in New Issue
Block a user