Ghidra is a software reverse engineering (SRE) framework
GP-2828 - Table marker performance
dragonmacher9e08b8c075ec
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.javaindex ea3aad4482..4efb793e2e 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java@@ -136,9 +136,8 @@ public class MarkerManager implements MarkerService {public MarkerSet createPointMarker(String name, String markerDescription, Program program,int priority, boolean showMarkers, boolean showNavigation, boolean colorBackground,Color color, Icon icon) {- MarkerSetImpl markers =- new PointMarkerSet(this, name, markerDescription, priority, showMarkers,- showNavigation, colorBackground, color, icon, program);+ MarkerSetImpl markers = new PointMarkerSet(this, name, markerDescription, priority,+ showMarkers, showNavigation, colorBackground, color, icon, program);insertMarkers(markers, program);return markers;}@@ -147,9 +146,8 @@ public class MarkerManager implements MarkerService {public MarkerSet createPointMarker(String name, String markerDescription, Program program,int priority, boolean showMarkers, boolean showNavigation, boolean colorBackground,Color color, Icon icon, boolean isPreferred) {- MarkerSetImpl markers =- new PointMarkerSet(this, name, markerDescription, priority, showMarkers,- showNavigation, colorBackground, color, icon, isPreferred, program);+ MarkerSetImpl markers = new PointMarkerSet(this, name, markerDescription, priority,+ showMarkers, showNavigation, colorBackground, color, icon, isPreferred, program);insertMarkers(markers, program);return markers;}@@ -311,7 +309,7 @@ public class MarkerManager implements MarkerService {/*** Call to signal that the markers for a given program have changed in some way, such as being* removed, changing colors or the active state being changed- *+ ** @param p the program associated with the markers*/void markersChanged(Program p) {@@ -394,6 +392,13 @@ public class MarkerManager implements MarkerService {insertMarkers(markers, program);}+ @Override+ public boolean isActiveMarkerForGroup(String groupName, MarkerSet markerSet, Program program) {+ Map<Program, MarkerSetImpl> markersByProgram = programMarkersByGroup.get(groupName);+ MarkerSetImpl previousMarkers = markersByProgram.get(program);+ return markerSet == previousMarkers;+ }+@Overridepublic void removeMarkerForGroup(String groupName, MarkerSet markers, Program program) {Map<Program, MarkerSetImpl> markersByProgram = programMarkersByGroup.get(groupName);diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/table/TableComponentProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/table/TableComponentProvider.javaindex 495df3b130..8358f573c1 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/table/TableComponentProvider.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/table/TableComponentProvider.java@@ -78,8 +78,8 @@ public class TableComponentProvider<T> extends ComponentProviderAdapterTableComponentProvider(TableServicePlugin plugin, String title, String name,GhidraProgramTableModel<T> model, String programName, GoToService gotoService,- MarkerService markerService, Color markerColor, Icon markerIcon,- String windowSubMenu, Navigatable navigatable) {+ MarkerService markerService, Color markerColor, Icon markerIcon, String windowSubMenu,+ Navigatable navigatable) {super(plugin.getTool(), name, plugin.getName());this.tableServicePlugin = plugin;@@ -238,17 +238,36 @@ public class TableComponentProvider<T> extends ComponentProviderAdapterreturn buffer.toString();}+ private void reloadMarkers() {+ if (markerSet == null) {+ return;+ }++ if (!markerService.isActiveMarkerForGroup(MarkerService.HIGHLIGHT_GROUP, markerSet,+ program)) {+ return; // we are not the active marker service; do not replace the active group+ }++ markerService.removeMarkerForGroup(MarkerService.HIGHLIGHT_GROUP, markerSet, program);+ loadMarkers();+ }+private void loadMarkers() {if (markerSet == null) {return;}+ if (markerService.isActiveMarkerForGroup(MarkerService.HIGHLIGHT_GROUP, markerSet,+ program)) {+ return; // already active; no need to load+ }+markerSet.clearAll();int n = model.getRowCount();for (int i = 0; i < n; i++) {- ProgramLocation loc = model.getProgramLocation(i, 0);- if (loc != null) {- markerSet.add(loc.getByteAddress());+ Address a = model.getAddress(i);+ if (a != null) {+ markerSet.add(a);}}@@ -328,7 +347,7 @@ public class TableComponentProvider<T> extends ComponentProviderAdapter@Overridepublic void tableChanged(TableModelEvent ev) {updateTitle();- loadMarkers();+ reloadMarkers();}public GhidraProgramTableModel<T> getModel() {@@ -347,9 +366,6 @@ public class TableComponentProvider<T> extends ComponentProviderAdapteractivationListenerList.remove(listener);}- /**- * @see docking.ComponentProvider#componentActivated()- */@Overridepublic void componentActivated() {loadMarkers();@@ -358,9 +374,6 @@ public class TableComponentProvider<T> extends ComponentProviderAdapter}}- /**- * @see docking.ComponentProvider#componentDeactived()- */@Overridepublic void componentDeactived() {for (ComponentProviderActivationListener listener : activationListenerList) {@@ -368,9 +381,6 @@ public class TableComponentProvider<T> extends ComponentProviderAdapter}}- /**- * @see docking.ComponentProvider#getWindowSubMenuName()- */@Overridepublic String getWindowSubMenuName() {return windowSubMenu;diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.javaindex 8d8e2e0528..d2a4488684 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java@@ -48,9 +48,7 @@ import ghidra.program.model.listing.Program;* a program has become deactivated. In this example usage markers are added and removed as the user* tabs through open programs.*/-@ServiceInfo(- defaultProvider = MarkerManagerPlugin.class,- description = "Service to manage navigation markers displayed around a scrollable window.")+@ServiceInfo(defaultProvider = MarkerManagerPlugin.class, description = "Service to manage navigation markers displayed around a scrollable window.")public interface MarkerService {/**@@ -209,7 +207,7 @@ public interface MarkerService {* Sets a marker set for a given group name. Any previous marker set associated with the given* group name will be removed from this marker service. This method is used to ensure that only* one marker set is used at any time for a give group.- *+ ** @param groupName The name to associate the marker set with.* @param markerSet The marker set to add to this service* @param program The program with which the markers are associated.@@ -217,15 +215,27 @@ public interface MarkerService {*/public void setMarkerForGroup(String groupName, MarkerSet markerSet, Program program);+ /**+ * Returns true if the given marker set is the current marker set for the given group.+ *+ * @param groupName The group name to check+ * @param markerSet The marker set to check+ * @param program The program with which the markers are associated.+ * @return true if the given marker set is the current marker set for the given group+ * @see #setMarkerForGroup(String, MarkerSet, Program)+ * @see #removeMarkerForGroup(String, MarkerSet, Program)+ */+ public boolean isActiveMarkerForGroup(String groupName, MarkerSet markerSet, Program program);+/*** Removes a marker set for a given group name. If the given marker set is not the marker set* associated with the given group name, then no action will be taken.- *+ ** @param groupName The name associated the marker set with.* @param markerSet The marker set to add to this service- * @param program The program with which the markers are associated. May be null if the marker- * is+ * @param program The program with which the markers are associated* @see #setMarkerForGroup(String, MarkerSet, Program)+ * @see #isActiveMarkerForGroup(String, MarkerSet, Program)*/public void removeMarkerForGroup(String groupName, MarkerSet markerSet, Program program);@@ -233,7 +243,7 @@ public interface MarkerService {* Returns the background color associated with the given program and address. Each markerSet* that supports background coloring is checked in priority order to see if it wants to specify* a background color for the given address.- *+ ** @param program the program to check for a background color.* @param address the address to check for a background color.* @return the background color to use for that address or null if no markers contain that@@ -244,14 +254,14 @@ public interface MarkerService {/*** Adds a change listener to be notified when markers are added/removed or the addresses in any* current markerSets are changed- *+ ** @param listener the listener*/public void addChangeListener(ChangeListener listener);/*** Removes the given change listener from the list of listeners to be notified of changes- *+ ** @param listener the listener*/public void removeChangeListener(ChangeListener listener);@@ -260,7 +270,7 @@ public interface MarkerService {* Sets the listener to be notified when the user double-clicks in the Marker Margin area. Note* that only one listener is allowed to be set at a time. If an attempt to set a second listener* occurs, then an IllegalStateException is thrown.- *+ ** @param listener the listener to be notified or null to remove the current listener* @throws IllegalStateException if a listener is already set.*/@@ -270,7 +280,7 @@ public interface MarkerService {* Create a new marker margin provider. The newly created provider is not added to the UI;* clients must install the newly created provider themselves. Note that you must keep a strong* reference to the provider, or it may not receive updates from the service.- *+ ** @return the new provider*/public MarkerMarginProvider createMarginProvider();@@ -279,7 +289,7 @@ public interface MarkerService {* Create a new marker overview provider. The newly created provider is not added to the UI;* clients must install the newly created provider themselves. Note that you must keep a strong* reference to the provider, or it may not receive updates from the service.- *+ ** @return the new provider*/public MarkerOverviewProvider createOverviewProvider();diff --git a/Ghidra/Features/Base/src/main/java/ghidra/util/table/GhidraProgramTableModel.java b/Ghidra/Features/Base/src/main/java/ghidra/util/table/GhidraProgramTableModel.javaindex 3289ea913b..683b37496e 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/util/table/GhidraProgramTableModel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/util/table/GhidraProgramTableModel.java@@ -17,6 +17,7 @@ package ghidra.util.table;import docking.widgets.table.threaded.ThreadedTableModel;import ghidra.framework.plugintool.ServiceProvider;+import ghidra.program.model.address.Address;import ghidra.program.model.listing.Program;import ghidra.util.task.TaskMonitor;@@ -64,4 +65,9 @@ public abstract class GhidraProgramTableModel<ROW_TYPE>public Program getDataSource() {return getProgram();}++ // most subclasses will override this to return an address+ public Address getAddress(int row) {+ return null;+ }}