[gnome-software] Remove unnecessary checks when using g_cancellable_cancel.



commit 882028b13cb0bdfbfa6d2baad443e6f90fb99fe1
Author: Robert Ancell <robert ancell canonical com>
Date:   Mon Sep 17 10:42:14 2018 +0200

    Remove unnecessary checks when using g_cancellable_cancel.
    
    g_cancellable_cancel works fine if the cancellable is NULL or already cancelled.

 lib/gs-plugin-loader.c         |  3 +--
 src/gs-application.c           |  6 ++----
 src/gs-auth-dialog.c           |  6 ++----
 src/gs-category-page.c         | 12 ++++--------
 src/gs-dbus-helper.c           |  6 ++----
 src/gs-extras-page.c           | 12 ++++--------
 src/gs-prefs-dialog.c          |  6 ++----
 src/gs-repos-dialog.c          |  6 ++----
 src/gs-search-page.c           |  9 +++------
 src/gs-shell-search-provider.c | 12 ++++--------
 src/gs-update-dialog.c         |  6 ++----
 src/gs-update-monitor.c        | 12 ++++--------
 src/gs-updates-page.c          | 18 ++++++------------
 13 files changed, 38 insertions(+), 76 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index e26b8531..02792f2c 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -3464,8 +3464,7 @@ gs_plugin_loader_job_timeout_cb (gpointer user_data)
 
        /* call the cancellable */
        g_debug ("cancelling job as it took too long");
-       if (!g_cancellable_is_cancelled (helper->cancellable))
-               g_cancellable_cancel (helper->cancellable);
+       g_cancellable_cancel (helper->cancellable);
 
        /* failed */
        helper->timeout_triggered = TRUE;
diff --git a/src/gs-application.c b/src/gs-application.c
index ae3fd239..45e22e33 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -982,10 +982,8 @@ gs_application_dispose (GObject *object)
 {
        GsApplication *app = GS_APPLICATION (object);
 
-       if (app->cancellable != NULL) {
-               g_cancellable_cancel (app->cancellable);
-               g_clear_object (&app->cancellable);
-       }
+       g_cancellable_cancel (app->cancellable);
+       g_clear_object (&app->cancellable);
 
        g_clear_object (&app->plugin_loader);
        g_clear_object (&app->shell);
diff --git a/src/gs-auth-dialog.c b/src/gs-auth-dialog.c
index 9eff3404..0b90fa81 100644
--- a/src/gs-auth-dialog.c
+++ b/src/gs-auth-dialog.c
@@ -254,10 +254,8 @@ gs_auth_dialog_dispose (GObject *object)
        g_clear_object (&dialog->app);
        g_clear_object (&dialog->auth);
 
-       if (dialog->cancellable != NULL) {
-               g_cancellable_cancel (dialog->cancellable);
-               g_clear_object (&dialog->cancellable);
-       }
+       g_cancellable_cancel (dialog->cancellable);
+       g_clear_object (&dialog->cancellable);
 
        G_OBJECT_CLASS (gs_auth_dialog_parent_class)->dispose (object);
 }
diff --git a/src/gs-category-page.c b/src/gs-category-page.c
index 06a7bf11..e3811c9f 100644
--- a/src/gs-category-page.c
+++ b/src/gs-category-page.c
@@ -328,10 +328,8 @@ gs_category_page_reload (GsPage *page)
        if (self->subcategory == NULL)
                return;
 
-       if (self->cancellable != NULL) {
-               g_cancellable_cancel (self->cancellable);
-               g_object_unref (self->cancellable);
-       }
+       g_cancellable_cancel (self->cancellable);
+       g_clear_object (&self->cancellable);
        self->cancellable = g_cancellable_new ();
 
        g_debug ("search using %s/%s",
@@ -546,10 +544,8 @@ gs_category_page_dispose (GObject *object)
 {
        GsCategoryPage *self = GS_CATEGORY_PAGE (object);
 
-       if (self->cancellable != NULL) {
-               g_cancellable_cancel (self->cancellable);
-               g_clear_object (&self->cancellable);
-       }
+       g_cancellable_cancel (self->cancellable);
+       g_clear_object (&self->cancellable);
 
        g_clear_object (&self->builder);
        g_clear_object (&self->category);
diff --git a/src/gs-dbus-helper.c b/src/gs-dbus-helper.c
index d9a59826..9fffb0a1 100644
--- a/src/gs-dbus-helper.c
+++ b/src/gs-dbus-helper.c
@@ -785,10 +785,8 @@ gs_dbus_helper_dispose (GObject *object)
 {
        GsDbusHelper *dbus_helper = GS_DBUS_HELPER (object);
 
-       if (dbus_helper->cancellable != NULL) {
-               g_cancellable_cancel (dbus_helper->cancellable);
-               g_clear_object (&dbus_helper->cancellable);
-       }
+       g_cancellable_cancel (dbus_helper->cancellable);
+       g_clear_object (&dbus_helper->cancellable);
 
        if (dbus_helper->dbus_own_name_id != 0) {
                g_bus_unown_name (dbus_helper->dbus_own_name_id);
diff --git a/src/gs-extras-page.c b/src/gs-extras-page.c
index fd23cf9a..f856bf20 100644
--- a/src/gs-extras-page.c
+++ b/src/gs-extras-page.c
@@ -666,10 +666,8 @@ gs_extras_page_load (GsExtrasPage *self, GPtrArray *array_search_data)
        guint i;
 
        /* cancel any pending searches */
-       if (self->search_cancellable != NULL) {
-               g_cancellable_cancel (self->search_cancellable);
-               g_object_unref (self->search_cancellable);
-       }
+       g_cancellable_cancel (self->search_cancellable);
+       g_clear_object (&self->search_cancellable);
        self->search_cancellable = g_cancellable_new ();
 
        if (array_search_data != NULL) {
@@ -1162,10 +1160,8 @@ gs_extras_page_dispose (GObject *object)
 {
        GsExtrasPage *self = GS_EXTRAS_PAGE (object);
 
-       if (self->search_cancellable != NULL) {
-               g_cancellable_cancel (self->search_cancellable);
-               g_clear_object (&self->search_cancellable);
-       }
+       g_cancellable_cancel (self->search_cancellable);
+       g_clear_object (&self->search_cancellable);
 
        g_clear_object (&self->sizegroup_image);
        g_clear_object (&self->sizegroup_name);
diff --git a/src/gs-prefs-dialog.c b/src/gs-prefs-dialog.c
index 605b6067..f85f9771 100644
--- a/src/gs-prefs-dialog.c
+++ b/src/gs-prefs-dialog.c
@@ -48,10 +48,8 @@ gs_prefs_dialog_dispose (GObject *object)
 {
        GsPrefsDialog *dialog = GS_PREFS_DIALOG (object);
        g_clear_object (&dialog->plugin_loader);
-       if (dialog->cancellable != NULL) {
-               g_cancellable_cancel (dialog->cancellable);
-               g_clear_object (&dialog->cancellable);
-       }
+       g_cancellable_cancel (dialog->cancellable);
+       g_clear_object (&dialog->cancellable);
        g_clear_object (&dialog->settings);
 
        G_OBJECT_CLASS (gs_prefs_dialog_parent_class)->dispose (object);
diff --git a/src/gs-repos-dialog.c b/src/gs-repos-dialog.c
index 6f8ebacd..eaf9907f 100644
--- a/src/gs-repos-dialog.c
+++ b/src/gs-repos-dialog.c
@@ -777,10 +777,8 @@ gs_repos_dialog_dispose (GObject *object)
                g_clear_object (&dialog->plugin_loader);
        }
 
-       if (dialog->cancellable != NULL) {
-               g_cancellable_cancel (dialog->cancellable);
-               g_clear_object (&dialog->cancellable);
-       }
+       g_cancellable_cancel (dialog->cancellable);
+       g_clear_object (&dialog->cancellable);
        g_clear_object (&dialog->settings);
        g_clear_object (&dialog->third_party_repo);
 
diff --git a/src/gs-search-page.c b/src/gs-search-page.c
index b305c18d..59787e1d 100644
--- a/src/gs-search-page.c
+++ b/src/gs-search-page.c
@@ -255,10 +255,8 @@ gs_search_page_load (GsSearchPage *self)
        g_autoptr(GsPluginJob) plugin_job = NULL;
 
        /* cancel any pending searches */
-       if (self->search_cancellable != NULL) {
-               g_cancellable_cancel (self->search_cancellable);
-               g_object_unref (self->search_cancellable);
-       }
+       g_cancellable_cancel (self->search_cancellable);
+       g_clear_object (&self->search_cancellable);
        self->search_cancellable = g_cancellable_new ();
 
        /* search for apps */
@@ -402,8 +400,7 @@ static void
 gs_search_page_cancel_cb (GCancellable *cancellable,
                           GsSearchPage *self)
 {
-       if (self->search_cancellable != NULL)
-               g_cancellable_cancel (self->search_cancellable);
+       g_cancellable_cancel (self->search_cancellable);
 }
 
 static void
diff --git a/src/gs-shell-search-provider.c b/src/gs-shell-search-provider.c
index c01d72cb..fa473b2c 100644
--- a/src/gs-shell-search-provider.c
+++ b/src/gs-shell-search-provider.c
@@ -167,10 +167,8 @@ execute_search (GsShellSearchProvider  *self,
 
        value = g_strjoinv (" ", terms);
 
-       if (self->cancellable != NULL) {
-               g_cancellable_cancel (self->cancellable);
-               g_clear_object (&self->cancellable);
-       }
+       g_cancellable_cancel (self->cancellable);
+       g_clear_object (&self->cancellable);
 
        /* don't attempt searches for a single character */
        if (g_strv_length (terms) == 1 &&
@@ -355,10 +353,8 @@ search_provider_dispose (GObject *obj)
 {
        GsShellSearchProvider *self = GS_SHELL_SEARCH_PROVIDER (obj);
 
-       if (self->cancellable != NULL) {
-               g_cancellable_cancel (self->cancellable);
-               g_clear_object (&self->cancellable);
-       }
+       g_cancellable_cancel (self->cancellable);
+       g_clear_object (&self->cancellable);
 
        if (self->metas_cache != NULL) {
                g_hash_table_destroy (self->metas_cache);
diff --git a/src/gs-update-dialog.c b/src/gs-update-dialog.c
index 42ba2613..f0627574 100644
--- a/src/gs-update-dialog.c
+++ b/src/gs-update-dialog.c
@@ -682,10 +682,8 @@ gs_update_dialog_dispose (GObject *object)
                dialog->back_entry_stack = NULL;
        }
 
-       if (dialog->cancellable != NULL) {
-               g_cancellable_cancel (dialog->cancellable);
-               g_clear_object (&dialog->cancellable);
-       }
+       g_cancellable_cancel (dialog->cancellable);
+       g_clear_object (&dialog->cancellable);
 
        g_clear_object (&dialog->plugin_loader);
 
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index fb6cf64b..f5766460 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -1057,14 +1057,10 @@ gs_update_monitor_dispose (GObject *object)
                monitor->network_changed_handler = 0;
        }
 
-       if (monitor->cancellable != NULL) {
-               g_cancellable_cancel (monitor->cancellable);
-               g_clear_object (&monitor->cancellable);
-       }
-       if (monitor->network_cancellable != NULL) {
-               g_cancellable_cancel (monitor->network_cancellable);
-               g_clear_object (&monitor->network_cancellable);
-       }
+       g_cancellable_cancel (monitor->cancellable);
+       g_clear_object (&monitor->cancellable);
+       g_cancellable_cancel (monitor->network_cancellable);
+       g_clear_object (&monitor->network_cancellable);
 
        stop_updates_check (monitor);
        stop_upgrades_check (monitor);
diff --git a/src/gs-updates-page.c b/src/gs-updates-page.c
index c48d2b78..15bbde72 100644
--- a/src/gs-updates-page.c
+++ b/src/gs-updates-page.c
@@ -804,10 +804,8 @@ gs_updates_page_get_new_updates (GsUpdatesPage *self)
        /* force a check for updates and download */
        gs_updates_page_set_state (self, GS_UPDATES_PAGE_STATE_ACTION_REFRESH);
 
-       if (self->cancellable_refresh != NULL) {
-               g_cancellable_cancel (self->cancellable_refresh);
-               g_object_unref (self->cancellable_refresh);
-       }
+       g_cancellable_cancel (self->cancellable_refresh);
+       g_clear_object (&self->cancellable_refresh);
        self->cancellable_refresh = g_cancellable_new ();
 
        plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
@@ -1391,14 +1389,10 @@ gs_updates_page_dispose (GObject *object)
 {
        GsUpdatesPage *self = GS_UPDATES_PAGE (object);
 
-       if (self->cancellable_refresh != NULL) {
-               g_cancellable_cancel (self->cancellable_refresh);
-               g_clear_object (&self->cancellable_refresh);
-       }
-       if (self->cancellable_upgrade_download != NULL) {
-               g_cancellable_cancel (self->cancellable_upgrade_download);
-               g_clear_object (&self->cancellable_upgrade_download);
-       }
+       g_cancellable_cancel (self->cancellable_refresh);
+       g_clear_object (&self->cancellable_refresh);
+       g_cancellable_cancel (self->cancellable_upgrade_download);
+       g_clear_object (&self->cancellable_upgrade_download);
 
        for (guint i = 0; i < GS_UPDATES_SECTION_KIND_LAST; i++) {
                if (self->sections[i] != NULL) {


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