Skip to content

Commit

Permalink
perf: Use hashset for fast comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Dec 12, 2023
1 parent 7f26c5b commit 1fad904
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/ui/views/patches_selector/patches_selector_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class PatchesSelectorViewModel extends BaseViewModel {
locator<PatcherViewModel>().selectedPatches;
PatchedApplication? selectedApp = locator<PatcherViewModel>().selectedApp;
String? patchesVersion = '';

Set<String> savedPatchNames = {};

bool isDefaultPatchesRepo() {
return _managerAPI.getPatchesRepo() == 'revanced/revanced-patches';
}
Expand All @@ -48,6 +51,9 @@ class PatchesSelectorViewModel extends BaseViewModel {
});
currentSelection.clear();
currentSelection.addAll(selectedPatches);

savedPatchNames = _managerAPI.getSavedPatches(selectedApp!.packageName).map((p) => p.name).toSet();

notifyListeners();
}

Expand Down Expand Up @@ -281,13 +287,10 @@ class PatchesSelectorViewModel extends BaseViewModel {
}

bool isPatchNew(Patch patch) {
final List<Patch> savedPatches =
_managerAPI.getSavedPatches(selectedApp!.packageName);
if (savedPatches.isEmpty) {
if (savedPatchNames.isEmpty) {
return false;
} else {
return !savedPatches
.any((p) => p.getSimpleName() == patch.getSimpleName());
return !savedPatchNames.contains(patch.name);
}
}

Expand Down

0 comments on commit 1fad904

Please sign in to comment.