gnucash maint: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Thu Dec 5 00:33:23 EST 2019
Updated via https://github.com/Gnucash/gnucash/commit/c06191a6 (commit)
via https://github.com/Gnucash/gnucash/commit/1c643856 (commit)
from https://github.com/Gnucash/gnucash/commit/7833c598 (commit)
commit c06191a6562d68a6151561936f487a6176d8045f
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Dec 5 10:16:45 2019 +0800
Transaction.c: avoid slow g_list_nth_data
diff --git a/libgnucash/engine/Transaction.c b/libgnucash/engine/Transaction.c
index 0a2243747..477ecb034 100644
--- a/libgnucash/engine/Transaction.c
+++ b/libgnucash/engine/Transaction.c
@@ -676,15 +676,25 @@ Transaction *
xaccTransClone (const Transaction *from)
{
Transaction *to = xaccTransCloneNoKvp (from);
- int i = 0;
- int length = g_list_length (from->splits);
+ GList *lfrom, *lto;
xaccTransBeginEdit (to);
qof_instance_copy_kvp (QOF_INSTANCE (to), QOF_INSTANCE (from));
- g_assert (g_list_length (to->splits) == length);
- for (i = 0; i < length; ++i)
- xaccSplitCopyKvp (g_list_nth_data (from->splits, i),
- g_list_nth_data (to->splits, i));
+ g_return_val_if_fail (g_list_length (to->splits) == g_list_length (from->splits),
+ NULL);
+
+ lfrom = from->splits;
+ lto = to->splits;
+
+ /* lfrom and lto are known to be of equal length via above
+ g_return_val_if_fail */
+ while (lfrom != NULL)
+ {
+ xaccSplitCopyKvp (lfrom->data, lto->data);
+ lfrom = lfrom->next;
+ lto = lto->next;
+ }
+
xaccTransCommitEdit (to);
return to;
}
commit 1c64385614ec8a14912b577fe6b2d4a4ba09627a
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Dec 5 09:57:23 2019 +0800
base-typemaps: avoid slow g_list_nth_data
scan GList via glist pointer links rather than incrementing index.
diff --git a/common/base-typemaps.i b/common/base-typemaps.i
index 33e9dffb7..98fbe3027 100644
--- a/common/base-typemaps.i
+++ b/common/base-typemaps.i
@@ -268,12 +268,12 @@ typedef char gchar;
%typemap(out) GList *, CommodityList *, SplitList *, AccountList *, LotList *,
MonetaryList *, PriceList *, EntryList * {
- guint i;
gpointer data;
+ GList *l;
PyObject *list = PyList_New(0);
- for (i = 0; i < g_list_length($1); i++)
+ for (l = $1; l != NULL; l = l->next)
{
- data = g_list_nth_data($1, i);
+ data = l->data;
if (GNC_IS_ACCOUNT(data))
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p_Account, 0));
else if (GNC_IS_SPLIT(data))
Summary of changes:
common/base-typemaps.i | 6 +++---
libgnucash/engine/Transaction.c | 22 ++++++++++++++++------
2 files changed, 19 insertions(+), 9 deletions(-)
More information about the gnucash-changes
mailing list