perf: Use hashset for fast comparison

This commit is contained in:
oSumAtrIX 2023-12-12 02:32:45 +01:00
parent 7f26c5bd45
commit 1fad90441c
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4

View File

@ -25,6 +25,9 @@ class PatchesSelectorViewModel extends BaseViewModel {
locator<PatcherViewModel>().selectedPatches; locator<PatcherViewModel>().selectedPatches;
PatchedApplication? selectedApp = locator<PatcherViewModel>().selectedApp; PatchedApplication? selectedApp = locator<PatcherViewModel>().selectedApp;
String? patchesVersion = ''; String? patchesVersion = '';
Set<String> savedPatchNames = {};
bool isDefaultPatchesRepo() { bool isDefaultPatchesRepo() {
return _managerAPI.getPatchesRepo() == 'revanced/revanced-patches'; return _managerAPI.getPatchesRepo() == 'revanced/revanced-patches';
} }
@ -48,6 +51,9 @@ class PatchesSelectorViewModel extends BaseViewModel {
}); });
currentSelection.clear(); currentSelection.clear();
currentSelection.addAll(selectedPatches); currentSelection.addAll(selectedPatches);
savedPatchNames = _managerAPI.getSavedPatches(selectedApp!.packageName).map((p) => p.name).toSet();
notifyListeners(); notifyListeners();
} }
@ -281,13 +287,10 @@ class PatchesSelectorViewModel extends BaseViewModel {
} }
bool isPatchNew(Patch patch) { bool isPatchNew(Patch patch) {
final List<Patch> savedPatches = if (savedPatchNames.isEmpty) {
_managerAPI.getSavedPatches(selectedApp!.packageName);
if (savedPatches.isEmpty) {
return false; return false;
} else { } else {
return !savedPatches return !savedPatchNames.contains(patch.name);
.any((p) => p.getSimpleName() == patch.getSimpleName());
} }
} }