[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.
pull/2153/head
Christopher Lam 5 months ago
parent a63a3e3ce3
commit cfc357a430

@ -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);

@ -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);

Loading…
Cancel
Save