mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
IDEA-321513 When searching for many usages, main time is spent in ShowUsagesAction.setPopupSize
GitOrigin-RevId: b7eb678ad28deffd95220235b738d1d75ebc3717
This commit is contained in:
committed by
intellij-monorepo-bot
parent
23330fa697
commit
079d84ff6b
@@ -1270,10 +1270,14 @@ public final class ShowUsagesAction extends AnAction implements PopupAction, Hin
|
||||
private static int columnMaxWidth(@NotNull JTable table, int col) {
|
||||
TableColumn column = table.getColumnModel().getColumn(col);
|
||||
int width = 0;
|
||||
for (int row = 0; row < table.getRowCount(); row++) {
|
||||
Component component = table.prepareRenderer(column.getCellRenderer(), row, col);
|
||||
for (int i = 0; i < table.getRowCount(); i++) {
|
||||
int row = i;
|
||||
ShowUsagesTable.MyModel model = (ShowUsagesTable.MyModel)table.getModel();
|
||||
int rendererWidth = model.getOrCalcCellWidth(i, col, () -> {
|
||||
Component component = table.prepareRenderer(column.getCellRenderer(), row, col);
|
||||
return component.getPreferredSize().width;
|
||||
});
|
||||
|
||||
int rendererWidth = component.getPreferredSize().width;
|
||||
width = Math.max(width, rendererWidth + table.getIntercellSpacing().width);
|
||||
}
|
||||
return width;
|
||||
|
||||
@@ -41,6 +41,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class ShowUsagesTable extends JBTable implements DataProvider {
|
||||
@@ -293,8 +294,11 @@ public final class ShowUsagesTable extends JBTable implements DataProvider {
|
||||
|
||||
static final class MyModel extends ListTableModel<UsageNode> implements ModelDiff.Model<UsageNode> {
|
||||
|
||||
private final CellSizesCache cellSizesCache;
|
||||
|
||||
private MyModel(@NotNull List<UsageNode> data, int cols) {
|
||||
super(cols(cols), data, 0);
|
||||
cellSizesCache = new CellSizesCache(data.size(), cols);
|
||||
}
|
||||
|
||||
private static ColumnInfo<UsageNode, UsageNode> @NotNull [] cols(int cols) {
|
||||
@@ -313,9 +317,11 @@ public final class ShowUsagesTable extends JBTable implements DataProvider {
|
||||
public void addToModel(int idx, UsageNode element) {
|
||||
if (idx < getRowCount()) {
|
||||
insertRow(idx, element);
|
||||
cellSizesCache.addLine(idx);
|
||||
}
|
||||
else {
|
||||
addRow(element);
|
||||
cellSizesCache.addLine();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,7 +329,47 @@ public final class ShowUsagesTable extends JBTable implements DataProvider {
|
||||
public void removeRangeFromModel(int start, int end) {
|
||||
for (int i = end; i >= start; i--) {
|
||||
removeRow(i);
|
||||
cellSizesCache.removeLine(i);
|
||||
}
|
||||
}
|
||||
|
||||
public int getOrCalcCellWidth(int row, int col, Supplier<Integer> supplier) {
|
||||
return cellSizesCache.getOrCalculate(row, col, supplier);
|
||||
}
|
||||
}
|
||||
|
||||
static class CellSizesCache {
|
||||
|
||||
private final List<Integer[]> table;
|
||||
private final int colsNumber;
|
||||
|
||||
private CellSizesCache(int rows, int cols) {
|
||||
colsNumber = cols;
|
||||
table = new ArrayList<>(rows);
|
||||
for (int i = 0; i < rows; i++) {
|
||||
table.add(new Integer[cols]);
|
||||
}
|
||||
}
|
||||
|
||||
void addLine() {
|
||||
table.add(new Integer[colsNumber]);
|
||||
}
|
||||
|
||||
void addLine(int row) {
|
||||
table.add(row, new Integer[colsNumber]);
|
||||
}
|
||||
|
||||
void removeLine(int row) {
|
||||
table.remove(row);
|
||||
}
|
||||
|
||||
int getOrCalculate(int row, int col, Supplier<Integer> supplier) {
|
||||
Integer cached = table.get(row)[col];
|
||||
if (cached != null) return cached;
|
||||
|
||||
Integer newVal = supplier.get();
|
||||
table.get(row)[col] = newVal;
|
||||
return newVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user