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;
PatchedApplication? selectedApp = locator<PatcherViewModel>().selectedApp;
String? patchesVersion = '';
Set<String> savedPatchNames = {};
bool isDefaultPatchesRepo() {
return _managerAPI.getPatchesRepo() == 'revanced/revanced-patches';
}
@ -48,6 +51,9 @@ class PatchesSelectorViewModel extends BaseViewModel {
});
currentSelection.clear();
currentSelection.addAll(selectedPatches);
savedPatchNames = _managerAPI.getSavedPatches(selectedApp!.packageName).map((p) => p.name).toSet();
notifyListeners();
}
@ -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);
}
}