gnucash stable: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Sun Dec 7 11:08:56 EST 2025
Updated via https://github.com/Gnucash/gnucash/commit/cfc357a4 (commit)
via https://github.com/Gnucash/gnucash/commit/a63a3e3c (commit)
from https://github.com/Gnucash/gnucash/commit/2f7e51cf (commit)
commit cfc357a430ae4f20093e39078be1a00cf278cea7
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Fri Dec 5 17:34:28 2025 +0800
[backend/xml] fast string setters for acct/trans/split
Avoids allocating/g_free temporary strings when DOM text
exists. Replaces dom_tree_to_text() with dom_node_to_text() fast-path
for Account, Transaction, and Split string setters.
diff --git a/libgnucash/backend/xml/gnc-account-xml-v2.cpp b/libgnucash/backend/xml/gnc-account-xml-v2.cpp
index 2a157baa2e..620150a068 100644
--- a/libgnucash/backend/xml/gnc-account-xml-v2.cpp
+++ b/libgnucash/backend/xml/gnc-account-xml-v2.cpp
@@ -175,6 +175,12 @@ static inline gboolean
set_string (xmlNodePtr node, Account* act,
void (*func) (Account* act, const gchar* txt))
{
+ if (auto txt = dom_node_to_text (node))
+ {
+ func (act,txt);
+ return TRUE;
+ }
+
gchar* txt = dom_tree_to_text (node);
g_return_val_if_fail (txt, FALSE);
diff --git a/libgnucash/backend/xml/gnc-transaction-xml-v2.cpp b/libgnucash/backend/xml/gnc-transaction-xml-v2.cpp
index 5d56224664..db0d577b27 100644
--- a/libgnucash/backend/xml/gnc-transaction-xml-v2.cpp
+++ b/libgnucash/backend/xml/gnc-transaction-xml-v2.cpp
@@ -203,6 +203,12 @@ static inline gboolean
set_spl_string (xmlNodePtr node, Split* spl,
void (*func) (Split* spl, const char* txt))
{
+ if (auto txt = dom_node_to_text (node))
+ {
+ func (spl, txt);
+ return TRUE;
+ }
+
gchar* tmp = dom_tree_to_text (node);
g_return_val_if_fail (tmp, FALSE);
@@ -251,6 +257,13 @@ static gboolean
spl_reconciled_state_handler (xmlNodePtr node, gpointer data)
{
struct split_pdata* pdata = static_cast<decltype (pdata)> (data);
+
+ if (auto txt = dom_node_to_text (node))
+ {
+ xaccSplitSetReconcile (pdata->split, txt[0]);
+ return TRUE;
+ }
+
gchar* tmp = dom_tree_to_text (node);
g_return_val_if_fail (tmp, FALSE);
@@ -399,6 +412,12 @@ static inline gboolean
set_tran_string (xmlNodePtr node, Transaction* trn,
void (*func) (Transaction* trn, const char* txt))
{
+ if (auto txt = dom_node_to_text (node))
+ {
+ func (trn, txt);
+ return TRUE;
+ }
+
gchar* tmp;
tmp = dom_tree_to_text (node);
commit a63a3e3ce39fac9f9e4bfd7c6acd09fb36324d03
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Fri Dec 5 16:38:53 2025 +0800
[sixtp-dom-parsers.cpp] introduce dom_node_to_text for solo text node
allocation-free
returns const char* or nullptr
diff --git a/libgnucash/backend/xml/sixtp-dom-parsers.cpp b/libgnucash/backend/xml/sixtp-dom-parsers.cpp
index bd2f4ed9b4..2619858462 100644
--- a/libgnucash/backend/xml/sixtp-dom-parsers.cpp
+++ b/libgnucash/backend/xml/sixtp-dom-parsers.cpp
@@ -35,6 +35,15 @@
static QofLogModule log_module = GNC_MOD_IO;
+const char*
+dom_node_to_text (xmlNodePtr node) noexcept
+{
+ if (node && node->children && node->children->type == XML_TEXT_NODE
+ && !node->children->next)
+ return reinterpret_cast<const char*>(node->children->content);
+ return nullptr;
+}
+
std::optional<GncGUID>
dom_tree_to_guid (xmlNodePtr node)
{
diff --git a/libgnucash/backend/xml/sixtp-dom-parsers.h b/libgnucash/backend/xml/sixtp-dom-parsers.h
index d23ae63606..37083438d9 100644
--- a/libgnucash/backend/xml/sixtp-dom-parsers.h
+++ b/libgnucash/backend/xml/sixtp-dom-parsers.h
@@ -45,6 +45,7 @@ gboolean dom_tree_valid_time64 (time64 ts, const xmlChar* name);
GDate* dom_tree_to_gdate (xmlNodePtr node);
gnc_numeric dom_tree_to_gnc_numeric (xmlNodePtr node);
gchar* dom_tree_to_text (xmlNodePtr tree);
+const char* dom_node_to_text (xmlNodePtr node) noexcept;
gboolean string_to_binary (const gchar* str, void** v, guint64* data_len);
gboolean dom_tree_create_instance_slots (xmlNodePtr node, QofInstance* inst);
Summary of changes:
libgnucash/backend/xml/gnc-account-xml-v2.cpp | 6 ++++++
libgnucash/backend/xml/gnc-transaction-xml-v2.cpp | 19 +++++++++++++++++++
libgnucash/backend/xml/sixtp-dom-parsers.cpp | 9 +++++++++
libgnucash/backend/xml/sixtp-dom-parsers.h | 1 +
4 files changed, 35 insertions(+)
More information about the gnucash-changes
mailing list