[gnome-software/gnome-40: 3/7] gs-app: Squash empty arrays to NULL in gs_app_set_version_history()




commit 7910276e5116db3f51dc5b088f3eb567e2472f17
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Apr 29 15:46:39 2021 +0100

    gs-app: Squash empty arrays to NULL in gs_app_set_version_history()
    
    This should save a little bit of memory. I have not updated the
    documentation to guarantee this behaviour because it’s a little unusual;
    simpler to allow callers to continue handling `NULL` and empty array
    cases explicitly.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1227

 lib/gs-app.c | 4 ++++
 1 file changed, 4 insertions(+)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 5ef7e9942..6c6bb6fe6 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -5366,6 +5366,10 @@ gs_app_set_version_history (GsApp *app, GPtrArray *version_history)
        GsAppPrivate *priv = gs_app_get_instance_private (app);
        g_autoptr(GMutexLocker) locker = NULL;
        g_return_if_fail (GS_IS_APP (app));
+
+       if (version_history != NULL && version_history->len == 0)
+               version_history = NULL;
+
        locker = g_mutex_locker_new (&priv->mutex);
        _g_set_ptr_array (&priv->version_history, version_history);
 }


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