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 2 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
15 changes: 8 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,14 @@ 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(" "));
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]", " ");

onFilter(filter.split(" "));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said in the other comment this method should be called with an empty array if showingHint is false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the note, I have addressed the above and pushed the changes.

}
}

protected void onFilter(String[] strings) {
Expand Down