mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[log] optimize RefsModel#refsToCommit
* Instead of searching for references each time, prepare the MultiMap Hash -> Collection<VcsRef> in the RefsModel constructor. * Remove myRefs and getAllRefs() since they are not used (the only caller is unused). * Change List<VcsRef> to Collection<VcsRef>: collection is actually what is needed, because references are (and should be) sorted by particular VcsLogRefManagers.
This commit is contained in:
@@ -2,7 +2,7 @@ package com.intellij.vcs.log.graph.render;
|
||||
|
||||
import com.intellij.vcs.log.VcsRef;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author erokhins
|
||||
@@ -10,9 +10,9 @@ import java.util.List;
|
||||
public class CommitCell {
|
||||
|
||||
private final String text;
|
||||
private final List<VcsRef> refsToThisCommit;
|
||||
private final Collection<VcsRef> refsToThisCommit;
|
||||
|
||||
public CommitCell(String text, List<VcsRef> refsToThisCommit) {
|
||||
public CommitCell(String text, Collection<VcsRef> refsToThisCommit) {
|
||||
this.text = text;
|
||||
this.refsToThisCommit = refsToThisCommit;
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class CommitCell {
|
||||
return text;
|
||||
}
|
||||
|
||||
public List<VcsRef> getRefsToThisCommit() {
|
||||
public Collection<VcsRef> getRefsToThisCommit() {
|
||||
return refsToThisCommit;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.intellij.vcs.log.graph.render;
|
||||
import com.intellij.vcs.log.VcsRef;
|
||||
import com.intellij.vcs.log.printmodel.GraphPrintCell;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
/**
|
||||
@@ -22,7 +22,7 @@ public class GraphCommitCell extends CommitCell {
|
||||
private final GraphPrintCell row;
|
||||
private final Kind kind;
|
||||
|
||||
public GraphCommitCell(GraphPrintCell row, Kind kind, String text, List<VcsRef> refsToThisCommit) {
|
||||
public GraphCommitCell(GraphPrintCell row, Kind kind, String text, Collection<VcsRef> refsToThisCommit) {
|
||||
super(text, refsToThisCommit);
|
||||
this.kind = kind;
|
||||
this.row = row;
|
||||
|
||||
@@ -182,16 +182,6 @@ public class DataPack {
|
||||
return new ArrayList<Node>(all);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public VcsRef findRefOfNode(Node node) {
|
||||
for (VcsRef ref : getRefsModel().getAllRefs()) {
|
||||
if (ref.getCommitHash().equals(node.getCommitHash())) {
|
||||
return ref;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Node> getCommitsInBranchAboveBase(Node base, Node branchHead) {
|
||||
List<Node> result = new ArrayList<Node>();
|
||||
Node node = branchHead;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.intellij.vcs.log.data;
|
||||
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.intellij.vcs.log.Hash;
|
||||
import com.intellij.vcs.log.VcsRef;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -13,24 +14,27 @@ import java.util.*;
|
||||
*/
|
||||
public class RefsModel {
|
||||
|
||||
@NotNull private final Collection<VcsRef> myRefs;
|
||||
@NotNull private final Collection<VcsRef> myBranches;
|
||||
@NotNull private final Set<Hash> myRefHashes;
|
||||
@NotNull private final MultiMap<Hash, VcsRef> myRefsToHashes;
|
||||
|
||||
public RefsModel(@NotNull Collection<VcsRef> allRefs) {
|
||||
myRefs = allRefs;
|
||||
|
||||
myBranches = ContainerUtil.filter(myRefs, new Condition<VcsRef>() {
|
||||
myBranches = ContainerUtil.filter(allRefs, new Condition<VcsRef>() {
|
||||
@Override
|
||||
public boolean value(VcsRef ref) {
|
||||
return ref.getType().isBranch();
|
||||
}
|
||||
});
|
||||
|
||||
myRefHashes = new HashSet<Hash>();
|
||||
for (VcsRef ref : myRefs) {
|
||||
myRefHashes.add(ref.getCommitHash());
|
||||
myRefsToHashes = prepareRefsMap(allRefs);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static MultiMap<Hash, VcsRef> prepareRefsMap(@NotNull Collection<VcsRef> refs) {
|
||||
MultiMap<Hash, VcsRef> map = MultiMap.create();
|
||||
for (VcsRef ref : refs) {
|
||||
map.putValue(ref.getCommitHash(), ref);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public boolean isBranchRef(@NotNull Hash commitHash) {
|
||||
@@ -43,21 +47,11 @@ public class RefsModel {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<VcsRef> refsToCommit(@NotNull Hash hash) {
|
||||
List<VcsRef> refs = new ArrayList<VcsRef>();
|
||||
if (myRefHashes.contains(hash)) {
|
||||
for (VcsRef ref : myRefs) {
|
||||
if (ref.getCommitHash().equals(hash)) {
|
||||
refs.add(ref);
|
||||
}
|
||||
}
|
||||
public Collection<VcsRef> refsToCommit(@NotNull Hash hash) {
|
||||
if (myRefsToHashes.containsKey(hash)) {
|
||||
return myRefsToHashes.get(hash);
|
||||
}
|
||||
return refs;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<VcsRef> getAllRefs() {
|
||||
return Collections.unmodifiableCollection(myRefs);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -27,6 +27,7 @@ import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -108,7 +109,7 @@ class DetailsPanel extends JPanel implements ListSelectionListener {
|
||||
|
||||
@NotNull
|
||||
private List<VcsRef> sortRefs(@NotNull Hash hash, @NotNull VirtualFile root) {
|
||||
List<VcsRef> refs = myLogDataHolder.getDataPack().getRefsModel().refsToCommit(hash);
|
||||
Collection<VcsRef> refs = myLogDataHolder.getDataPack().getRefsModel().refsToCommit(hash);
|
||||
return myLogDataHolder.getLogProvider(root).getReferenceManager().sort(refs);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import javax.swing.table.TableCellRenderer;
|
||||
import java.awt.*;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
|
||||
import static com.intellij.vcs.log.graph.render.PrintParameters.HEIGHT_CELL;
|
||||
import static com.intellij.vcs.log.graph.render.PrintParameters.WIDTH_NODE;
|
||||
@@ -85,7 +85,7 @@ public class GraphCommitCellRender implements TableCellRenderer {
|
||||
|
||||
int countCells = cell.getPrintCell().countCell();
|
||||
int padding = countCells * WIDTH_NODE;
|
||||
List<VcsRef> refs = cell.getRefsToThisCommit();
|
||||
Collection<VcsRef> refs = cell.getRefsToThisCommit();
|
||||
if (!refs.isEmpty()) {
|
||||
VirtualFile root = refs.iterator().next().getRoot(); // all refs are from the same commit => they have the same root
|
||||
refs = myDataHolder.getLogProvider(root).getReferenceManager().sort(refs);
|
||||
|
||||
@@ -7,8 +7,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.awt.*;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.intellij.vcs.log.graph.render.PrintParameters.HEIGHT_CELL;
|
||||
@@ -95,7 +95,7 @@ public class RefPainter {
|
||||
g2.drawPolygon(polygon);
|
||||
}
|
||||
|
||||
public int padding(@NotNull List<VcsRef> refs, @NotNull FontRenderContext renderContext) {
|
||||
public int padding(@NotNull Collection<VcsRef> refs, @NotNull FontRenderContext renderContext) {
|
||||
float p = 0;
|
||||
for (VcsRef ref : refs) {
|
||||
p += paddingStr(ref.getName(), renderContext);
|
||||
@@ -103,7 +103,7 @@ public class RefPainter {
|
||||
return Math.round(p);
|
||||
}
|
||||
|
||||
public Map<Integer, VcsRef> draw(@NotNull Graphics2D g2, @NotNull List<VcsRef> refs, int startPadding, int maxWidth) {
|
||||
public Map<Integer, VcsRef> draw(@NotNull Graphics2D g2, @NotNull Collection<VcsRef> refs, int startPadding, int maxWidth) {
|
||||
float currentPadding = startPadding;
|
||||
g2.setFont(DEFAULT_FONT);
|
||||
g2.setStroke(new BasicStroke(1.5f));
|
||||
|
||||
@@ -12,8 +12,8 @@ import com.intellij.vcs.log.printmodel.GraphPrintCell;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author erokhins
|
||||
@@ -67,7 +67,7 @@ public class GraphTableModel extends AbstractTableModel {
|
||||
case COMMIT_COLUMN:
|
||||
GraphPrintCell graphPrintCell = myDataPack.getPrintCellModel().getGraphPrintCell(rowIndex);
|
||||
String message = "";
|
||||
List<VcsRef> refs = Collections.emptyList();
|
||||
Collection<VcsRef> refs = Collections.emptyList();
|
||||
if (data != null) {
|
||||
message = data.getSubject();
|
||||
refs = myDataPack.getRefsModel().refsToCommit(data.getHash());
|
||||
|
||||
Reference in New Issue
Block a user