[gnome-software] core: Only define refine(), not refine_app(), where possible
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] core: Only define refine(), not refine_app(), where possible
- Date: Wed, 22 Apr 2020 12:03:08 +0000 (UTC)
commit 15d39630bb74bd9f6e813bcbdd85b7173f3b7df0
Author: Philip Withnall <withnall endlessm com>
Date: Wed Apr 8 13:49:17 2020 +0100
core: Only define refine(), not refine_app(), where possible
This combines a lot of `gs_plugin_loader_call_vfunc()` calls when
refining a non-trivial list of apps; and it sometimes allows common
setup code (especially locking) to be shared between all apps in the
list, rather than being repeated for each `refine()_app` call.
This should improve performance slightly, depending on the size of app
lists being handled.
Signed-off-by: Philip Withnall <withnall endlessm com>
plugins/core/gs-plugin-appstream.c | 34 ++++++++++++++-----------
plugins/core/gs-plugin-desktop-menu-path.c | 32 +++++++++++++++++++-----
plugins/core/gs-plugin-hardcoded-blacklist.c | 28 ++++++++++++++++-----
plugins/core/gs-plugin-icons.c | 32 +++++++++++++++++++-----
plugins/core/gs-plugin-key-colors-metadata.c | 28 ++++++++++++++++-----
plugins/core/gs-plugin-key-colors.c | 32 +++++++++++++++++++-----
plugins/core/gs-plugin-provenance-license.c | 37 +++++++++++++++++++++++-----
plugins/core/gs-plugin-provenance.c | 37 +++++++++++++++++++++++-----
plugins/core/gs-plugin-rewrite-resource.c | 28 ++++++++++++++++-----
9 files changed, 225 insertions(+), 63 deletions(-)
---
diff --git a/plugins/core/gs-plugin-appstream.c b/plugins/core/gs-plugin-appstream.c
index 037653c1..6ba3aaca 100644
--- a/plugins/core/gs-plugin-appstream.c
+++ b/plugins/core/gs-plugin-appstream.c
@@ -786,29 +786,33 @@ gs_plugin_refine_from_pkgname (GsPlugin *plugin,
}
gboolean
-gs_plugin_refine_app (GsPlugin *plugin,
- GsApp *app,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+gs_plugin_refine (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
gboolean found = FALSE;
- /* not us */
- if (gs_app_get_bundle_kind (app) != AS_BUNDLE_KIND_PACKAGE &&
- gs_app_get_bundle_kind (app) != AS_BUNDLE_KIND_UNKNOWN)
- return TRUE;
-
/* check silo is valid */
if (!gs_plugin_appstream_check_silo (plugin, cancellable, error))
return FALSE;
- /* find by ID then fall back to package name */
- if (!gs_plugin_refine_from_id (plugin, app, flags, &found, error))
- return FALSE;
- if (!found) {
- if (!gs_plugin_refine_from_pkgname (plugin, app, flags, error))
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GsApp *app = gs_app_list_index (list, i);
+
+ /* not us */
+ if (gs_app_get_bundle_kind (app) != AS_BUNDLE_KIND_PACKAGE &&
+ gs_app_get_bundle_kind (app) != AS_BUNDLE_KIND_UNKNOWN)
+ return TRUE;
+
+ /* find by ID then fall back to package name */
+ if (!gs_plugin_refine_from_id (plugin, app, flags, &found, error))
return FALSE;
+ if (!found) {
+ if (!gs_plugin_refine_from_pkgname (plugin, app, flags, error))
+ return FALSE;
+ }
}
/* success */
diff --git a/plugins/core/gs-plugin-desktop-menu-path.c b/plugins/core/gs-plugin-desktop-menu-path.c
index a3e8806b..1a65d1ca 100644
--- a/plugins/core/gs-plugin-desktop-menu-path.c
+++ b/plugins/core/gs-plugin-desktop-menu-path.c
@@ -40,12 +40,12 @@ _gs_app_has_desktop_group (GsApp *app, const gchar *desktop_group)
}
/* adds the menu-path for applications */
-gboolean
-gs_plugin_refine_app (GsPlugin *plugin,
- GsApp *app,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+static gboolean
+refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
const gchar *strv[] = { "", NULL, NULL };
const GsDesktopData *msdata;
@@ -88,3 +88,23 @@ gs_plugin_refine_app (GsPlugin *plugin,
gs_app_set_menu_path (app, (gchar **) strv);
return TRUE;
}
+
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ /* nothing to do here */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_MENU_PATH) == 0)
+ return TRUE;
+
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GsApp *app = gs_app_list_index (list, i);
+ if (!refine_app (plugin, app, flags, cancellable, error))
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/plugins/core/gs-plugin-hardcoded-blacklist.c b/plugins/core/gs-plugin-hardcoded-blacklist.c
index 5034090f..48d02187 100644
--- a/plugins/core/gs-plugin-hardcoded-blacklist.c
+++ b/plugins/core/gs-plugin-hardcoded-blacklist.c
@@ -22,12 +22,12 @@ gs_plugin_initialize (GsPlugin *plugin)
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
}
-gboolean
-gs_plugin_refine_app (GsPlugin *plugin,
- GsApp *app,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+static gboolean
+refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
guint i;
const gchar *app_globs[] = {
@@ -59,3 +59,19 @@ gs_plugin_refine_app (GsPlugin *plugin,
return TRUE;
}
+
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GsApp *app = gs_app_list_index (list, i);
+ if (!refine_app (plugin, app, flags, cancellable, error))
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/plugins/core/gs-plugin-icons.c b/plugins/core/gs-plugin-icons.c
index a9b76721..0abf79f1 100644
--- a/plugins/core/gs-plugin-icons.c
+++ b/plugins/core/gs-plugin-icons.c
@@ -252,12 +252,12 @@ gs_plugin_icons_load_cached (GsPlugin *plugin, AsIcon *icon, GError **error)
return g_object_ref (as_icon_get_pixbuf (icon));
}
-gboolean
-gs_plugin_refine_app (GsPlugin *plugin,
- GsApp *app,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+static gboolean
+refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
GPtrArray *icons;
guint i;
@@ -312,3 +312,23 @@ gs_plugin_refine_app (GsPlugin *plugin,
return TRUE;
}
+
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ /* nothing to do here */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON) == 0)
+ return TRUE;
+
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GsApp *app = gs_app_list_index (list, i);
+ if (!refine_app (plugin, app, flags, cancellable, error))
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/plugins/core/gs-plugin-key-colors-metadata.c b/plugins/core/gs-plugin-key-colors-metadata.c
index 93fa9844..a468ac6a 100644
--- a/plugins/core/gs-plugin-key-colors-metadata.c
+++ b/plugins/core/gs-plugin-key-colors-metadata.c
@@ -15,12 +15,12 @@ gs_plugin_initialize (GsPlugin *plugin)
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "key-colors");
}
-gboolean
-gs_plugin_refine_app (GsPlugin *plugin,
- GsApp *app,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+static gboolean
+refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
GPtrArray *key_colors;
const gchar *keys[] = {
@@ -70,3 +70,19 @@ gs_plugin_refine_app (GsPlugin *plugin,
return TRUE;
}
+
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GsApp *app = gs_app_list_index (list, i);
+ if (!refine_app (plugin, app, flags, cancellable, error))
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/plugins/core/gs-plugin-key-colors.c b/plugins/core/gs-plugin-key-colors.c
index c438e811..d109dcbf 100644
--- a/plugins/core/gs-plugin-key-colors.c
+++ b/plugins/core/gs-plugin-key-colors.c
@@ -142,12 +142,12 @@ gs_plugin_key_colors_set_for_pixbuf (GsApp *app, GdkPixbuf *pb, guint number)
}
}
-gboolean
-gs_plugin_refine_app (GsPlugin *plugin,
- GsApp *app,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+static gboolean
+refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
GdkPixbuf *pb;
g_autoptr(GdkPixbuf) pb_small = NULL;
@@ -172,3 +172,23 @@ gs_plugin_refine_app (GsPlugin *plugin,
gs_plugin_key_colors_set_for_pixbuf (app, pb_small, 10);
return TRUE;
}
+
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ /* nothing to do here */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_KEY_COLORS) == 0)
+ return TRUE;
+
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GsApp *app = gs_app_list_index (list, i);
+ if (!refine_app (plugin, app, flags, cancellable, error))
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/plugins/core/gs-plugin-provenance-license.c b/plugins/core/gs-plugin-provenance-license.c
index 2bf7dfc4..ece80799 100644
--- a/plugins/core/gs-plugin-provenance-license.c
+++ b/plugins/core/gs-plugin-provenance-license.c
@@ -95,12 +95,12 @@ gs_plugin_destroy (GsPlugin *plugin)
g_object_unref (priv->settings);
}
-gboolean
-gs_plugin_refine_app (GsPlugin *plugin,
- GsApp *app,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+static gboolean
+refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *origin;
@@ -124,3 +124,28 @@ gs_plugin_refine_app (GsPlugin *plugin,
return TRUE;
}
+
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+
+ /* nothing to do here */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE) == 0)
+ return TRUE;
+ /* nothing to search */
+ if (priv->sources == NULL || priv->sources[0] == NULL)
+ return TRUE;
+
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GsApp *app = gs_app_list_index (list, i);
+ if (!refine_app (plugin, app, flags, cancellable, error))
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/plugins/core/gs-plugin-provenance.c b/plugins/core/gs-plugin-provenance.c
index 06cb5eb0..e70e5001 100644
--- a/plugins/core/gs-plugin-provenance.c
+++ b/plugins/core/gs-plugin-provenance.c
@@ -69,12 +69,12 @@ gs_plugin_destroy (GsPlugin *plugin)
g_object_unref (priv->settings);
}
-gboolean
-gs_plugin_refine_app (GsPlugin *plugin,
- GsApp *app,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+static gboolean
+refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *origin;
@@ -113,3 +113,28 @@ gs_plugin_refine_app (GsPlugin *plugin,
}
return TRUE;
}
+
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+
+ /* nothing to do here */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE) == 0)
+ return TRUE;
+ /* nothing to search */
+ if (priv->sources == NULL || priv->sources[0] == NULL)
+ return TRUE;
+
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GsApp *app = gs_app_list_index (list, i);
+ if (!refine_app (plugin, app, flags, cancellable, error))
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/plugins/core/gs-plugin-rewrite-resource.c b/plugins/core/gs-plugin-rewrite-resource.c
index cf66b746..23ee6080 100644
--- a/plugins/core/gs-plugin-rewrite-resource.c
+++ b/plugins/core/gs-plugin-rewrite-resource.c
@@ -17,12 +17,12 @@ gs_plugin_initialize (GsPlugin *plugin)
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
}
-gboolean
-gs_plugin_refine_app (GsPlugin *plugin,
- GsApp *app,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+static gboolean
+refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
const gchar *keys[] = {
"GnomeSoftware::AppTile-css",
@@ -54,3 +54,19 @@ gs_plugin_refine_app (GsPlugin *plugin,
}
return TRUE;
}
+
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GsApp *app = gs_app_list_index (list, i);
+ if (!refine_app (plugin, app, flags, cancellable, error))
+ return FALSE;
+ }
+
+ return TRUE;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]