[gnome-software: 2/3] gs-appstream: Tidy up another iteration over nodes




commit 85d3c297ef93b7c95c4ab6fd3b0348122c7c5d1e
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Oct 6 10:52:48 2021 +0100

    gs-appstream: Tidy up another iteration over nodes
    
    This iteration was not buggy and did not leak, but can now be refactored
    to use a `for` loop and `node_set_to_next()`. This reduces the number of
    lines of code, makes the termination condition for the loop easier to
    verify, and factors out the complicated bit of the reference handling.
    
    This commit introduces no functional changes.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 lib/gs-appstream.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
---
diff --git a/lib/gs-appstream.c b/lib/gs-appstream.c
index 283186abe..df91dd0fd 100644
--- a/lib/gs-appstream.c
+++ b/lib/gs-appstream.c
@@ -65,11 +65,8 @@ static gchar *
 gs_appstream_format_description (XbNode *root, GError **error)
 {
        g_autoptr(GString) str = g_string_new (NULL);
-       g_autoptr(XbNode) n = xb_node_get_child (root);
-
-       while (n != NULL) {
-               g_autoptr(XbNode) n2 = NULL;
 
+       for (g_autoptr(XbNode) n = xb_node_get_child (root); n != NULL; node_set_to_next (&n)) {
                /* support <p>, <ul>, <ol> and <li>, ignore all else */
                if (g_strcmp0 (xb_node_get_element (n), "p") == 0) {
                        const gchar *node_text = xb_node_get_text (n);
@@ -109,9 +106,6 @@ gs_appstream_format_description (XbNode *root, GError **error)
                        }
                        g_string_append (str, "\n");
                }
-
-               n2 = xb_node_get_next (n);
-               g_set_object (&n, n2);
        }
 
        /* remove extra newlines */


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