[devhelp] DhLink: improve struct



commit 74e03a73438bc9c456691676b8ffda2428226d14
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Dec 7 17:22:17 2017 +0100

    DhLink: improve struct
    
    - More logical field order.
    - Better documentation.
    - Do not align field names on the same column, when adding a field with
      a long type, it's cumbersome to adapt the alignment for all fields.

 src/dh-link.c |   31 +++++++++++++++++++------------
 1 files changed, 19 insertions(+), 12 deletions(-)
---
diff --git a/src/dh-link.c b/src/dh-link.c
index 493c160..478ab38 100644
--- a/src/dh-link.c
+++ b/src/dh-link.c
@@ -38,22 +38,29 @@
  */
 
 struct _DhLink {
-        /* FIXME: Those two could exist only for book to save some
-         * memory.
+        guint ref_count;
+
+        /* FIXME: it is possible to optimize this struct to use less memory, by
+         * having only one pointer for the book, for example with an union and a
+         * secondary struct for @base_path + @book_id.
+         */
+
+        /* @base_path and @book_id are set only for links of @type
+         * DH_LINK_TYPE_BOOK.
          */
-        gchar       *book_id;
-        gchar       *base_path;
+        gchar *base_path;
+        gchar *book_id;
 
-        DhLink      *book;
+        /* @book is set only for links of @type != DH_LINK_TYPE_BOOK. */
+        DhLink *book;
 
-        gchar       *name;
-        gchar       *name_collation_key;
-        gchar       *relative_url;
+        gchar *name;
+        gchar *name_collation_key;
 
-        guint        ref_count;
+        gchar *relative_url;
 
-        DhLinkType   type : 8;
-        DhLinkFlags  flags : 8;
+        DhLinkType type : 8;
+        DhLinkFlags flags : 8;
 };
 
 /* If the relative_url is empty. */
@@ -65,8 +72,8 @@ G_DEFINE_BOXED_TYPE (DhLink, dh_link,
 static void
 link_free (DhLink *link)
 {
-        g_free (link->book_id);
         g_free (link->base_path);
+        g_free (link->book_id);
         g_free (link->name);
         g_free (link->name_collation_key);
         g_free (link->relative_url);


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