Skip to content

Optimize applyFilter() to Avoid Redundant String Operations #11284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions app/src/cc/arduino/contributions/ui/FilterJTextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,16 @@ private void spawnTimer() {
}

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) {
Expand Down