From b3e29a81fdfd784b1dc9229577fa289ff2c13afa Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sun, 14 Jun 2026 10:30:02 +0800 Subject: [PATCH] [qofid.cpp] use ctor/dtor for QofCollection which will make it easier to construct in-place in book->hash_of_collections --- libgnucash/engine/qofid.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) 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(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(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; } /* =============================================================== */