From 1fad90441cda88d6632307adc207adb0eadf4964 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Tue, 12 Dec 2023 02:32:45 +0100 Subject: [PATCH] perf: Use hashset for fast comparison --- .../patches_selector_viewmodel.dart | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/ui/views/patches_selector/patches_selector_viewmodel.dart b/lib/ui/views/patches_selector/patches_selector_viewmodel.dart index 173c1f53..6b6d7d24 100644 --- a/lib/ui/views/patches_selector/patches_selector_viewmodel.dart +++ b/lib/ui/views/patches_selector/patches_selector_viewmodel.dart @@ -25,6 +25,9 @@ class PatchesSelectorViewModel extends BaseViewModel { locator().selectedPatches; PatchedApplication? selectedApp = locator().selectedApp; String? patchesVersion = ''; + + Set 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 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); } }