[gnome-software] trivial: Use g_strv_contains instead of manually iterating



commit 3e314ee6ba318caa672b5934830b0f397e9dfa83
Author: Robert Ancell <robert ancell canonical com>
Date:   Mon Mar 14 16:53:23 2016 +1300

    trivial: Use g_strv_contains instead of manually iterating

 src/plugins/gs-plugin-packagekit-refresh.c |    8 +-------
 src/plugins/gs-plugin-provenance.c         |    9 +++------
 src/plugins/gs-plugin-xdg-app.c            |    8 +-------
 3 files changed, 5 insertions(+), 20 deletions(-)
---
diff --git a/src/plugins/gs-plugin-packagekit-refresh.c b/src/plugins/gs-plugin-packagekit-refresh.c
index 551b035..722f8ff 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -228,13 +228,7 @@ gs_plugin_packagekit_refresh_content_type_matches (const gchar *filename,
        tmp = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
 
        /* match any */
-       *matches = FALSE;
-       for (i = 0; mimetypes[i] != NULL; i++) {
-               if (g_strcmp0 (tmp, mimetypes[i]) == 0) {
-                       *matches = TRUE;
-                       break;
-               }
-       }
+       *matches = tmp != NULL && g_strv_contains (mimetypes, tmp);
        return TRUE;
 }
 
diff --git a/src/plugins/gs-plugin-provenance.c b/src/plugins/gs-plugin-provenance.c
index 0ecad6d..0fee230 100644
--- a/src/plugins/gs-plugin-provenance.c
+++ b/src/plugins/gs-plugin-provenance.c
@@ -106,7 +106,6 @@ gs_plugin_refine_app (GsPlugin *plugin,
 {
        const gchar *origin;
        const gchar * const *sources;
-       guint i;
 
        /* not required */
        if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE) == 0)
@@ -137,11 +136,9 @@ gs_plugin_refine_app (GsPlugin *plugin,
                return TRUE;
        if (g_str_has_prefix (origin + 1, "installed:"))
                origin += 10;
-       for (i = 0; sources[i] != NULL; i++) {
-               if (g_strcmp0 (origin + 1, sources[i]) == 0) {
-                       gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
-                       break;
-               }
+       if (g_strv_contains (sources, origin + 1)) {
+               gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
+               return TRUE;
        }
        return TRUE;
 }
diff --git a/src/plugins/gs-plugin-xdg-app.c b/src/plugins/gs-plugin-xdg-app.c
index cee2006..387cdfd 100644
--- a/src/plugins/gs-plugin-xdg-app.c
+++ b/src/plugins/gs-plugin-xdg-app.c
@@ -1422,13 +1422,7 @@ gs_plugin_xdg_app_content_type_matches (const gchar *filename,
        tmp = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
 
        /* match any */
-       *matches = FALSE;
-       for (i = 0; mimetypes[i] != NULL; i++) {
-               if (g_strcmp0 (tmp, mimetypes[i]) == 0) {
-                       *matches = TRUE;
-                       break;
-               }
-       }
+       *matches = tmp != NULL && g_strv_contains (mimetypes, tmp);
        return TRUE;
 }
 


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