[gnome-software/wip/hughsie/fix-alternates-regression: 9/12] trivial: Add easy-to-read flags for when dedupe should be done



commit 8a0bba465e70432d67a77a9766202aec96cccec3
Author: Richard Hughes <richard hughsie com>
Date:   Mon Oct 8 17:23:43 2018 +0100

    trivial: Add easy-to-read flags for when dedupe should be done

 lib/gs-app-list.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
---
diff --git a/lib/gs-app-list.c b/lib/gs-app-list.c
index 4694862e..9f3c16dc 100644
--- a/lib/gs-app-list.c
+++ b/lib/gs-app-list.c
@@ -355,13 +355,20 @@ gs_app_list_check_for_duplicate (GsAppList *list, GsApp *app)
        return FALSE;
 }
 
+typedef enum {
+       GS_APP_LIST_ADD_FLAG_NONE               = 0,
+       GS_APP_LIST_ADD_FLAG_CHECK_FOR_DUPE     = 1 << 0,
+       GS_APP_LIST_ADD_FLAG_LAST
+} GsAppListAddFlag;
+
 static void
-gs_app_list_add_safe (GsAppList *list, GsApp *app, gboolean check_for_dupes)
+gs_app_list_add_safe (GsAppList *list, GsApp *app, GsAppListAddFlag flag)
 {
        const gchar *id;
 
        /* check for duplicate */
-       if (check_for_dupes && !gs_app_list_check_for_duplicate (list, app))
+       if ((flag & GS_APP_LIST_ADD_FLAG_CHECK_FOR_DUPE) > 0 &&
+           !gs_app_list_check_for_duplicate (list, app))
                return;
 
        /* if we're lazy-loading the ID then we can't use the ID hash */
@@ -404,7 +411,7 @@ gs_app_list_add (GsAppList *list, GsApp *app)
        g_return_if_fail (GS_IS_APP_LIST (list));
        g_return_if_fail (GS_IS_APP (app));
        locker = g_mutex_locker_new (&list->mutex);
-       gs_app_list_add_safe (list, app, TRUE);
+       gs_app_list_add_safe (list, app, GS_APP_LIST_ADD_FLAG_CHECK_FOR_DUPE);
 
        /* recalculate global state */
        gs_app_list_invalidate_state (list);
@@ -476,7 +483,7 @@ gs_app_list_add_list (GsAppList *list, GsAppList *donor)
        /* add each app */
        for (i = 0; i < donor->array->len; i++) {
                GsApp *app = gs_app_list_index (donor, i);
-               gs_app_list_add_safe (list, app, TRUE);
+               gs_app_list_add_safe (list, app, GS_APP_LIST_ADD_FLAG_CHECK_FOR_DUPE);
        }
 
        /* recalculate global state */
@@ -579,7 +586,7 @@ gs_app_list_filter (GsAppList *list, GsAppListFilterFunc func, gpointer user_dat
        for (i = 0; i < old->array->len; i++) {
                app = gs_app_list_index (old, i);
                if (func (app, user_data))
-                       gs_app_list_add_safe (list, app, FALSE);
+                       gs_app_list_add_safe (list, app, GS_APP_LIST_ADD_FLAG_NONE);
        }
 }
 
@@ -871,7 +878,7 @@ gs_app_list_filter_duplicates (GsAppList *list, GsAppListFilterFlags flags)
        for (guint i = 0; i < old->array->len; i++) {
                GsApp *app = gs_app_list_index (old, i);
                if (g_hash_table_contains (kept_apps, app))
-                       gs_app_list_add_safe (list, app, FALSE);
+                       gs_app_list_add_safe (list, app, GS_APP_LIST_ADD_FLAG_NONE);
        }
 }
 
@@ -896,7 +903,7 @@ gs_app_list_copy (GsAppList *list)
        new = gs_app_list_new ();
        for (i = 0; i < gs_app_list_length (list); i++) {
                GsApp *app = gs_app_list_index (list, i);
-               gs_app_list_add_safe (new, app, FALSE);
+               gs_app_list_add_safe (new, app, GS_APP_LIST_ADD_FLAG_NONE);
        }
        return new;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]