Skip to content

Commit c22b8ba

Browse files
committed
Eliminate O(n^2) status removal in DashboardTreeTableModel
updateChannelNodes called statuses.remove(status) inside a loop over child nodes. With an ArrayList, each remove is O(n), making the update O(channels × statuses). Collected matched statuses in a HashSet and called removeAll once after the loop, reducing to O(n + m). Signed-off-by: Nico Piel <nico.piel@hotmail.de>
1 parent 5423492 commit c22b8ba

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

client/src/com/mirth/connect/client/ui/DashboardTreeTableModel.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,14 @@ private void updateChannelNodes(List<DashboardStatus> statuses, MutableTreeTable
498498
}
499499

500500
private void updateChannelNodes(Map<String, DashboardStatus> statusMap, List<DashboardStatus> statuses, MutableTreeTableNode parent) {
501+
Set<DashboardStatus> matched = new HashSet<>();
501502
for (int i = 0; i < parent.getChildCount(); i++) {
502503
AbstractDashboardTableNode node = (AbstractDashboardTableNode) parent.getChildAt(i);
503504

504505
if (statusMap.containsKey(node.getDashboardStatus().getKey())) {
505506
// Remove channels that do exist from the list of statuses so they will not be added again later.
506507
DashboardStatus status = statusMap.get(node.getDashboardStatus().getKey());
507-
statuses.remove(status);
508+
matched.add(status);
508509
// Update the channel status
509510
node.setDashboardStatus(status);
510511
modelSupport.firePathChanged(new TreePath(getPathToRoot(node)));
@@ -513,6 +514,7 @@ private void updateChannelNodes(Map<String, DashboardStatus> statusMap, List<Das
513514
updateConnector(statusMap, node);
514515
}
515516
}
517+
statuses.removeAll(matched);
516518
}
517519

518520
private void removeLingeringChannelNodes(List<DashboardStatus> statuses, MutableTreeTableNode root) {

0 commit comments

Comments
 (0)