gnucash maint: Avoid unnecessary g_list_length in equality functions
Christopher Lam
clam at code.gnucash.org
Thu Oct 21 07:36:12 EDT 2021
Updated via https://github.com/Gnucash/gnucash/commit/f40dbb8c (commit)
from https://github.com/Gnucash/gnucash/commit/f0970c8e (commit)
commit f40dbb8c28885a0c44cb4fcadd871acd2b77504a
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Tue Oct 19 19:15:13 2021 +0800
Avoid unnecessary g_list_length in equality functions
diff --git a/libgnucash/engine/qofquery.cpp b/libgnucash/engine/qofquery.cpp
index c17261896..22793bf43 100644
--- a/libgnucash/engine/qofquery.cpp
+++ b/libgnucash/engine/qofquery.cpp
@@ -1458,23 +1458,26 @@ gboolean qof_query_equal (const QofQuery *q1, const QofQuery *q2)
if (q1 == q2) return TRUE;
if (!q1 || !q2) return FALSE;
- if (g_list_length (q1->terms) != g_list_length (q2->terms)) return FALSE;
if (q1->max_results != q2->max_results) return FALSE;
- for (or1 = q1->terms, or2 = q2->terms; or1;
- or1 = or1->next, or2 = or2->next)
+ for (or1 = q1->terms, or2 = q2->terms; or1 || or2;
+ or1 = or1->next, or2 = or2->next)
{
GList *and1, *and2;
+ if (!or1 || !or2)
+ return FALSE;
and1 = static_cast<GList*>(or1->data);
and2 = static_cast<GList*>(or2->data);
- if (g_list_length (and1) != g_list_length (and2)) return FALSE;
-
- for ( ; and1; and1 = and1->next, and2 = and2->next)
+ for (; and1 || and2; and1 = and1->next, and2 = and2->next)
+ {
+ if (!and1 || !and2)
+ return FALSE;
if (!qof_query_term_equal (static_cast<QofQueryTerm*>(and1->data),
static_cast<QofQueryTerm*>(and2->data)))
return FALSE;
+ }
}
if (!qof_query_sort_equal (&(q1->primary_sort), &(q2->primary_sort)))
diff --git a/libgnucash/engine/qofquerycore.cpp b/libgnucash/engine/qofquerycore.cpp
index f9c8b980d..51c530113 100644
--- a/libgnucash/engine/qofquerycore.cpp
+++ b/libgnucash/engine/qofquerycore.cpp
@@ -732,9 +732,10 @@ guid_predicate_equal (const QofQueryPredData *p1, const QofQueryPredData *p2)
GList *l1 = pd1->guids, *l2 = pd2->guids;
if (pd1->options != pd2->options) return FALSE;
- if (g_list_length (l1) != g_list_length (l2)) return FALSE;
- for ( ; l1 ; l1 = l1->next, l2 = l2->next)
+ for (; l1 || l2; l1 = l1->next, l2 = l2->next)
{
+ if (!l1 || !l2)
+ return FALSE;
if (!guid_equal (static_cast<GncGUID*>(l1->data),
static_cast<GncGUID*>(l2->data)))
return FALSE;
@@ -1525,9 +1526,10 @@ choice_predicate_equal (const QofQueryPredData *p1, const QofQueryPredData *p2)
GList *l1 = pd1->guids, *l2 = pd2->guids;
if (pd1->options != pd2->options) return FALSE;
- if (g_list_length (l1) != g_list_length (l2)) return FALSE;
- for ( ; l1 ; l1 = l1->next, l2 = l2->next)
+ for (; l1 || l2; l1 = l1->next, l2 = l2->next)
{
+ if (!l1 || !l2)
+ return FALSE;
if (!guid_equal (static_cast<GncGUID*>(l1->data),
static_cast<GncGUID*>(l2->data)))
return FALSE;
Summary of changes:
libgnucash/engine/qofquery.cpp | 15 +++++++++------
libgnucash/engine/qofquerycore.cpp | 10 ++++++----
2 files changed, 15 insertions(+), 10 deletions(-)
More information about the gnucash-changes
mailing list