mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-21 10:52:14 +01:00
Optimize applyFilter() to Avoid Redundant String Operations (#11284)
if 'showingHint' == true, then many potentially expensive String operations are being executed on an empty string. This change wraps these operations in an if block which will only run them when needed.
This commit is contained in:
parent
f4f98cf25e
commit
3f0699a949
@ -101,13 +101,16 @@ public class FilterJTextField extends JTextField {
|
||||
}
|
||||
|
||||
public void applyFilter() {
|
||||
String filter = showingHint ? "" : getText();
|
||||
filter = filter.toLowerCase();
|
||||
|
||||
// Replace anything but 0-9, a-z, or : with a space
|
||||
filter = filter.replaceAll("[^\\x30-\\x39^\\x61-\\x7a^\\x3a]", " ");
|
||||
|
||||
onFilter(filter.split(" "));
|
||||
String[] filteredText = new String[0];
|
||||
if (!showingHint) {
|
||||
String filter = getText().toLowerCase();
|
||||
|
||||
// Replace anything but 0-9, a-z, or : with a space
|
||||
filter = filter.replaceAll("[^\\x30-\\x39^\\x61-\\x7a^\\x3a]", " ");
|
||||
|
||||
filteredText = filter.split(" ");
|
||||
}
|
||||
onFilter(filteredText);
|
||||
}
|
||||
|
||||
protected void onFilter(String[] strings) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user