From 31776250891ff3b2a7d904ff0c5fad612ac2e009 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Wed, 4 Oct 2023 00:20:29 +0400 Subject: [PATCH] refactor: cleanup --- .../patches/components/LithoFilterPatch.java | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/patches/components/LithoFilterPatch.java b/app/src/main/java/app/revanced/integrations/patches/components/LithoFilterPatch.java index 9b82cf0c51..3b86164084 100644 --- a/app/src/main/java/app/revanced/integrations/patches/components/LithoFilterPatch.java +++ b/app/src/main/java/app/revanced/integrations/patches/components/LithoFilterPatch.java @@ -15,22 +15,20 @@ abstract class FilterGroup { final static class FilterGroupResult { private SettingsEnum setting; - private boolean filtered; private int matchedIndex; // In the future it might be useful to include which pattern matched, // but for now that is not needed. FilterGroupResult() { - this(null, false, -1); + this(null, -1); } - FilterGroupResult(SettingsEnum setting, boolean filtered, int matchedIndex) { - setValues(setting, filtered, matchedIndex); + FilterGroupResult(SettingsEnum setting, int matchedIndex) { + setValues(setting, matchedIndex); } - public void setValues(SettingsEnum setting, boolean filtered, int matchedIndex) { + public void setValues(SettingsEnum setting, int matchedIndex) { this.setting = setting; - this.filtered = filtered; this.matchedIndex = matchedIndex; } @@ -43,7 +41,7 @@ public SettingsEnum getSetting() { } public boolean isFiltered() { - return filtered; + return matchedIndex >= 0; } /** @@ -101,11 +99,10 @@ public StringFilterGroup(final SettingsEnum setting, final String... filters) { @Override public FilterGroupResult check(final String string) { - final boolean isEnabled = isEnabled(); - final int indexOf = isEnabled + final int indexOf = isEnabled() ? ReVancedUtils.indexOfFirstFound(string, filters) : -1; - return new FilterGroupResult(setting, isEnabled, indexOf); + return new FilterGroupResult(setting, indexOf); } } @@ -179,7 +176,6 @@ private synchronized void buildFailurePatterns() { @Override public FilterGroupResult check(final byte[] bytes) { - var matched = false; int matchedIndex = -1; if (isEnabled()) { if (failurePatterns == null) { @@ -188,12 +184,11 @@ public FilterGroupResult check(final byte[] bytes) { for (int i = 0, length = filters.length; i < length; i++) { matchedIndex = indexOf(bytes, filters[i], failurePatterns[i]); if (matchedIndex >= 0) { - matched = true; break; } } } - return new FilterGroupResult(setting, matched, matchedIndex); + return new FilterGroupResult(setting, matchedIndex); } } @@ -233,7 +228,7 @@ protected final synchronized void buildSearch() { search.addPattern(pattern, (textSearched, matchedStartIndex, callbackParameter) -> { if (group.isEnabled()) { FilterGroup.FilterGroupResult result = (FilterGroup.FilterGroupResult) callbackParameter; - result.setValues(group.setting, true, matchedStartIndex); + result.setValues(group.setting, matchedStartIndex); return true; } return false;