gnucash stable: [qofid.cpp] use ctor/dtor for QofCollection

Christopher Lam clam at code.gnucash.org
Sun Jun 14 20:43:30 EDT 2026


Updated	 via  https://github.com/Gnucash/gnucash/commit/56467754 (commit)
	from  https://github.com/Gnucash/gnucash/commit/b102df32 (commit)



commit 56467754f1258a872b38be3989ce196d95e9bbf4
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Jun 14 10:30:02 2026 +0800

    [qofid.cpp] use ctor/dtor for QofCollection
    
    which will make it easier to construct in-place in book->hash_of_collections

diff --git a/libgnucash/engine/qofid.cpp b/libgnucash/engine/qofid.cpp
index 3e47ff9158..f649c281a6 100644
--- a/libgnucash/engine/qofid.cpp
+++ b/libgnucash/engine/qofid.cpp
@@ -40,6 +40,16 @@ struct QofCollection_s
 
     GHashTable * hash_of_entities;
     gpointer     data;       /* place where object class can hang arbitrary data */
+
+    QofCollection_s (QofIdType type) : e_type{static_cast<QofIdType>(CACHE_INSERT(type))}
+                                     , is_dirty{FALSE}
+                                     , hash_of_entities{guid_hash_table_new()}
+                                     , data{NULL} {}
+    ~QofCollection_s ()
+    {
+        CACHE_REMOVE (e_type);
+        g_hash_table_destroy (hash_of_entities);
+    }
 };
 
 /* =============================================================== */
@@ -47,24 +57,13 @@ struct QofCollection_s
 QofCollection *
 qof_collection_new (QofIdType type)
 {
-    QofCollection *col;
-    col = g_new0(QofCollection, 1);
-    col->e_type = static_cast<QofIdType>(CACHE_INSERT (type));
-    col->is_dirty = FALSE;
-    col->hash_of_entities = guid_hash_table_new();
-    col->data = NULL;
-    return col;
+    return new QofCollection (type);
 }
 
 void
 qof_collection_destroy (QofCollection *col)
 {
-    CACHE_REMOVE (col->e_type);
-    g_hash_table_destroy(col->hash_of_entities);
-    col->e_type = NULL;
-    col->hash_of_entities = NULL;
-    col->data = NULL;   /** XXX there should be a destroy notifier for this */
-    g_free (col);
+    delete col;
 }
 
 /* =============================================================== */



Summary of changes:
 libgnucash/engine/qofid.cpp | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)



More information about the gnucash-changes mailing list