mirror of
https://github.com/nasa/trick.git
synced 2024-12-18 12:56:26 +00:00
1746 trick view variable search causes large spike in cpu usage (#1786)
* Add new "greedy search" option to toggle multi-threaded variable search * Back down to a single thread * Fixed a typo. --------- Co-authored-by: Hong Chen <hong.chen-1@nasa.gov>
This commit is contained in:
parent
c007cfc88a
commit
d34844e76c
@ -115,7 +115,8 @@ public class SearchPanel extends JXPanel {
|
||||
listModel.clear();
|
||||
searcher.search(textField.getText().trim(),
|
||||
caseSensitiveCheckBox.isSelected(),
|
||||
regularExpressionCheckBox.isSelected());
|
||||
regularExpressionCheckBox.isSelected(),
|
||||
greedySearchCheckBox.isSelected());
|
||||
if (searcher.elementCount == 0) {
|
||||
progressBar.setIndeterminate(true);
|
||||
}
|
||||
@ -136,6 +137,12 @@ public class SearchPanel extends JXPanel {
|
||||
setToolTipText("Toggle regular expression searching.");
|
||||
}};
|
||||
|
||||
/** toggles case-insensitive searching */
|
||||
JCheckBox greedySearchCheckBox = new JCheckBox("Greedy Search") {{
|
||||
setName("greedySearchCheckBox");
|
||||
setToolTipText("Toggle multi-threaded search (Warning: may cause overruns).");
|
||||
}};
|
||||
|
||||
/** search results list model */
|
||||
EfficientListModel listModel = new EfficientListModel();
|
||||
|
||||
@ -227,6 +234,7 @@ public class SearchPanel extends JXPanel {
|
||||
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||
add(caseSensitiveCheckBox);
|
||||
add(regularExpressionCheckBox);
|
||||
add(greedySearchCheckBox);
|
||||
}});
|
||||
}}, constraints);
|
||||
|
||||
@ -306,6 +314,7 @@ public class SearchPanel extends JXPanel {
|
||||
textField.setEnabled(enabled);
|
||||
caseSensitiveCheckBox.setEnabled(enabled);
|
||||
regularExpressionCheckBox.setEnabled(enabled);
|
||||
greedySearchCheckBox.setEnabled(enabled);
|
||||
list.setEnabled(enabled);
|
||||
list.setComponentPopupMenu(enabled ? popupMenu : null);
|
||||
}
|
||||
|
@ -89,9 +89,10 @@ public class Searcher {
|
||||
* @param targetText the text for which to search
|
||||
* @param caseSensitive enables case sensitive searching
|
||||
* @param regularExpression enables regular expression searching
|
||||
* @param greedSearch enabled multi-threaded search
|
||||
*/
|
||||
public void search(final String targetText, final boolean caseSensitive,
|
||||
final boolean regularExpression) {
|
||||
final boolean regularExpression, final boolean greedySearch) {
|
||||
|
||||
final SearchFunction searchFunction = regularExpression ?
|
||||
|
||||
@ -124,7 +125,11 @@ public class Searcher {
|
||||
|
||||
cancelSearch();
|
||||
count = 0;
|
||||
threads = Runtime.getRuntime().availableProcessors();
|
||||
if (greedySearch) {
|
||||
threads = Runtime.getRuntime().availableProcessors();
|
||||
} else {
|
||||
threads = 1;
|
||||
}
|
||||
propertyChangeListener.propertyChange(new PropertyChangeEvent(this, "progress", 0, 0));
|
||||
final ConcurrentLinkedQueue<SieTemplate> roots = new ConcurrentLinkedQueue<SieTemplate>(rootTemplates);
|
||||
executorService = Executors.newFixedThreadPool(threads);
|
||||
|
Loading…
Reference in New Issue
Block a user