mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-11-22 08:57:17 -06:00
Shortcut g_list_length comparison against small numbers
It's more efficient to test node && node->next etc when testing GList length against small numbers
This commit is contained in:
parent
e94ee3bfad
commit
b5f5129f7d
@ -1446,7 +1446,7 @@ gnc_main_window_delete_event (GtkWidget *window,
|
||||
if (already_dead)
|
||||
return TRUE;
|
||||
|
||||
if (g_list_length (active_windows) > 1)
|
||||
if (active_windows && active_windows->next)
|
||||
{
|
||||
gint response;
|
||||
GtkWidget *dialog;
|
||||
@ -1478,7 +1478,7 @@ gnc_main_window_delete_event (GtkWidget *window,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (g_list_length(active_windows) > 1)
|
||||
if (active_windows && active_windows->next)
|
||||
return FALSE;
|
||||
|
||||
already_dead = gnc_main_window_quit(GNC_MAIN_WINDOW(window));
|
||||
@ -3348,7 +3348,7 @@ gnc_main_window_close_page (GncPluginPage *page)
|
||||
/* remove the preference callbacks from the main window */
|
||||
gnc_main_window_remove_prefs (window);
|
||||
}
|
||||
if (window && g_list_length (active_windows) > 1)
|
||||
if (window && active_windows && active_windows->next)
|
||||
gtk_widget_destroy (GTK_WIDGET(window));
|
||||
}
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ gnc_imap_dialog_delete (ImapDialog *imap_dialog)
|
||||
list = gtk_tree_selection_get_selected_rows (selection, &fmodel);
|
||||
|
||||
// Make sure we have some rows selected
|
||||
if (g_list_length (list) == 0)
|
||||
if (list == NULL)
|
||||
return;
|
||||
|
||||
// reset the invalid map total
|
||||
@ -645,7 +645,7 @@ get_imap_info (ImapDialog *imap_dialog, Account *acc, const gchar *category, con
|
||||
else
|
||||
head = IMAP_FRAME;
|
||||
|
||||
if (g_list_length (imap_list) > 0)
|
||||
if (imap_list != NULL)
|
||||
{
|
||||
PINFO("List length is %d", g_list_length (imap_list));
|
||||
|
||||
|
@ -3237,7 +3237,7 @@ multi_post_invoice_cb (GtkWindow *dialog, GList *invoice_list, gpointer user_dat
|
||||
gboolean test;
|
||||
InvoiceWindow *iw;
|
||||
|
||||
if (g_list_length(invoice_list) == 0)
|
||||
if (invoice_list == NULL)
|
||||
return;
|
||||
// Get the posting parameters for these invoices
|
||||
iw = gnc_ui_invoice_edit(dialog, invoice_list->data);
|
||||
@ -3287,7 +3287,7 @@ multi_print_invoice_cb (GtkWindow *dialog, GList *invoice_list, gpointer user_da
|
||||
{
|
||||
struct multi_edit_invoice_data meid;
|
||||
|
||||
if (g_list_length(invoice_list) == 0)
|
||||
if (invoice_list == NULL)
|
||||
return;
|
||||
|
||||
meid.user_data = user_data;
|
||||
|
@ -1735,7 +1735,7 @@ static GList *select_txn_lots (GtkWindow *parent, Transaction *txn, Account **po
|
||||
/* If the txn has both APAR splits linked to a business lot and
|
||||
* splits that are not, issue a warning some will be discarded.
|
||||
*/
|
||||
if (has_no_lot_apar_splits && (g_list_length (txn_lots) > 0))
|
||||
if (has_no_lot_apar_splits && (txn_lots != NULL))
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
char *split_str = g_strdup ("");
|
||||
|
@ -366,7 +366,7 @@ selection_changed_cb (GtkTreeSelection *selection, gpointer data)
|
||||
PricesDialog *pdb_dialog = data;
|
||||
GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(pdb_dialog->remove_view));
|
||||
GList *rows = gtk_tree_selection_get_selected_rows (selection, &model);
|
||||
gboolean have_rows = (g_list_length (rows) > 0 ? TRUE : FALSE);
|
||||
gboolean have_rows = (rows != NULL);
|
||||
|
||||
change_source_flag (PRICE_REMOVE_SOURCE_COMM, have_rows, pdb_dialog);
|
||||
g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
|
||||
@ -547,7 +547,7 @@ gnc_prices_dialog_add_clicked (GtkWidget *widget, gpointer data)
|
||||
}
|
||||
else if (comm_list) // selection contains price parent rows
|
||||
{
|
||||
if (g_list_length (comm_list) == 1) // make sure it is only one parent
|
||||
if (!comm_list->next) // make sure it is only one parent
|
||||
{
|
||||
price = gnc_price_create (pdb_dialog->book);
|
||||
gnc_price_set_commodity (price, comm_list->data);
|
||||
|
@ -579,7 +579,7 @@ gnc_sxed_check_endpoint (GncSxEditorDialog *sxed)
|
||||
|
||||
g_date_clear (&nextDate, 1);
|
||||
gnc_frequency_save_to_recurrence (sxed->gncfreq, &schedule, &startDate);
|
||||
if (g_list_length (schedule) > 0)
|
||||
if (schedule != NULL)
|
||||
{
|
||||
g_date_subtract_days (&startDate, 1);
|
||||
recurrenceListNextInstance (schedule, &startDate, &nextDate);
|
||||
@ -1766,7 +1766,7 @@ _sx_engine_event_handler (QofInstance *ent, QofEventId event_type, gpointer user
|
||||
book = qof_instance_get_book (QOF_INSTANCE (acct));
|
||||
affected_sxes = gnc_sx_get_sxes_referencing_account (book, acct);
|
||||
|
||||
if (g_list_length (affected_sxes) == 0)
|
||||
if (affected_sxes == NULL)
|
||||
return;
|
||||
|
||||
{
|
||||
|
@ -836,7 +836,7 @@ gnc_sxed_check_consistent (GncSxEditorDialog2 *sxed)
|
||||
|
||||
g_date_clear (&nextDate, 1);
|
||||
gnc_frequency_save_to_recurrence (sxed->gncfreq, &schedule, &startDate);
|
||||
if (g_list_length (schedule) > 0)
|
||||
if (schedule != NULL)
|
||||
{
|
||||
g_date_subtract_days (&startDate, 1);
|
||||
recurrenceListNextInstance (schedule, &startDate, &nextDate);
|
||||
@ -1704,7 +1704,7 @@ _sx_engine_event_handler (QofInstance *ent, QofEventId event_type, gpointer user
|
||||
book = qof_instance_get_book (QOF_INSTANCE (acct));
|
||||
affected_sxes = gnc_sx_get_sxes_referencing_account (book, acct);
|
||||
|
||||
if (g_list_length (affected_sxes) == 0)
|
||||
if (affected_sxes == NULL)
|
||||
return;
|
||||
|
||||
{
|
||||
|
@ -1154,9 +1154,11 @@ dialog_response_cb (GtkDialog *dialog, gint response_id, GncSxSinceLastRunDialog
|
||||
// - [?] ability to create transactions
|
||||
{
|
||||
GList *unbound_variables;
|
||||
gint unbound_len;
|
||||
unbound_variables = gnc_sx_instance_model_check_variables (app_dialog->editing_model->instances);
|
||||
PINFO ("%d variables unbound", g_list_length (unbound_variables));
|
||||
if (g_list_length (unbound_variables) > 0)
|
||||
unbound_len = g_list_length (unbound_variables);
|
||||
PINFO ("%d variables unbound", unbound_len);
|
||||
if (unbound_len > 0)
|
||||
{
|
||||
// focus first variable
|
||||
GncSxVariableNeeded *first_unbound;
|
||||
|
@ -593,7 +593,7 @@ gnc_plugin_page_account_tree_open (Account *account, GtkWindow *win)
|
||||
page_list = gnc_gobject_tracking_get_list(GNC_PLUGIN_PAGE_ACCOUNT_TREE_NAME);
|
||||
|
||||
// If we have a window, look for account page in that window
|
||||
if (g_list_length ((GList*)page_list) != 0)
|
||||
if (page_list != NULL)
|
||||
{
|
||||
if (win != NULL)
|
||||
{
|
||||
@ -1500,7 +1500,7 @@ account_subaccount (Account* account)
|
||||
{
|
||||
Account* subaccount = NULL;
|
||||
GList *subs = gnc_account_get_children (account);
|
||||
if (g_list_length (subs) == 1)
|
||||
if (subs && !subs->next)
|
||||
subaccount = subs->data;
|
||||
g_list_free (subs);
|
||||
return subaccount;
|
||||
|
@ -756,7 +756,7 @@ gnc_plugin_page_sx_list_cmd_edit (GtkAction *action, GncPluginPageSxList *page)
|
||||
|
||||
selection = gtk_tree_view_get_selection (priv->tree_view);
|
||||
selected_paths = gtk_tree_selection_get_selected_rows (selection, &model);
|
||||
if (g_list_length (selected_paths) == 0)
|
||||
if (selected_paths == NULL)
|
||||
{
|
||||
g_warning ("no selection edit.");
|
||||
return;
|
||||
@ -792,7 +792,7 @@ gnc_plugin_page_sx_list_cmd_edit2 (GtkAction *action, GncPluginPageSxList *page)
|
||||
|
||||
selection = gtk_tree_view_get_selection (priv->tree_view);
|
||||
selected_paths = gtk_tree_selection_get_selected_rows (selection, &model);
|
||||
if (g_list_length (selected_paths) == 0)
|
||||
if (selected_paths == NULL)
|
||||
{
|
||||
g_warning ("no selection edit.");
|
||||
return;
|
||||
@ -853,7 +853,7 @@ gnc_plugin_page_sx_list_cmd_delete (GtkAction *action, GncPluginPageSxList *page
|
||||
|
||||
selection = gtk_tree_view_get_selection (priv->tree_view);
|
||||
selected_paths = gtk_tree_selection_get_selected_rows (selection, &model);
|
||||
if (g_list_length (selected_paths) == 0)
|
||||
if (selected_paths == NULL)
|
||||
{
|
||||
g_warning ("no selection for delete.");
|
||||
return;
|
||||
|
@ -429,7 +429,7 @@ gnc_ledger_display_gl (void)
|
||||
tRoot = gnc_book_get_template_root (gnc_get_current_book());
|
||||
al = gnc_account_get_descendants (tRoot);
|
||||
|
||||
if (g_list_length (al) != 0)
|
||||
if (al != NULL)
|
||||
xaccQueryAddAccountMatch (query, al, QOF_GUID_MATCH_NONE, QOF_QUERY_AND);
|
||||
|
||||
g_list_free (al);
|
||||
|
@ -556,7 +556,7 @@ recurrenceWeekendAdjustFromString(const gchar *str)
|
||||
gboolean
|
||||
recurrenceListIsSemiMonthly(GList *recurrences)
|
||||
{
|
||||
if (g_list_length(recurrences) != 2)
|
||||
if (!(recurrences && recurrences->next && !recurrences->next->next))
|
||||
return FALSE;
|
||||
|
||||
// should be a "semi-monthly":
|
||||
@ -879,9 +879,10 @@ recurrenceListCmp(GList *a, GList *b)
|
||||
{
|
||||
Recurrence *most_freq_a, *most_freq_b;
|
||||
|
||||
g_return_val_if_fail(g_list_length(a) != 0 && g_list_length(b) != 0, 0);
|
||||
g_return_val_if_fail(g_list_length(a) != 0, -1);
|
||||
g_return_val_if_fail(g_list_length(b) != 0, 1);
|
||||
if (!a)
|
||||
return (b ? -1 : 0);
|
||||
else if (!b)
|
||||
return 1;
|
||||
|
||||
most_freq_a = (Recurrence*)g_list_nth_data(g_list_sort(a, (GCompareFunc)recurrenceCmp), 0);
|
||||
most_freq_b = (Recurrence*)g_list_nth_data(g_list_sort(b, (GCompareFunc)recurrenceCmp), 0);
|
||||
|
@ -89,7 +89,6 @@ static void * search(QofBook * book, const gchar *id, void * object, GncSearchTy
|
||||
void *c;
|
||||
GList *result;
|
||||
QofQuery *q;
|
||||
gint len;
|
||||
QofQueryPredData* string_pred_data;
|
||||
|
||||
PINFO("Type = %d", type);
|
||||
@ -123,8 +122,7 @@ static void * search(QofBook * book, const gchar *id, void * object, GncSearchTy
|
||||
result = qof_query_run (q);
|
||||
|
||||
// now compare _exactly_
|
||||
len = g_list_length (result);
|
||||
if (result && (len > 0))
|
||||
if (result != NULL)
|
||||
{
|
||||
result = g_list_first (result);
|
||||
|
||||
|
@ -676,7 +676,7 @@ void qof_query_add_term (QofQuery *q, QofQueryParamList *param_list,
|
||||
qs = qof_query_create ();
|
||||
query_init (qs, qt);
|
||||
|
||||
if (qof_query_has_terms (q))
|
||||
if (q->terms != NULL)
|
||||
qr = qof_query_merge (q, qs, op);
|
||||
else
|
||||
qr = qof_query_merge (q, qs, QOF_QUERY_OR);
|
||||
@ -701,7 +701,8 @@ void qof_query_purge_terms (QofQuery *q, QofQueryParamList *param_list)
|
||||
qt = static_cast<QofQueryTerm*>(_and_->data);
|
||||
if (!param_list_cmp (qt->param_list, param_list))
|
||||
{
|
||||
if (g_list_length (static_cast<GList*>(_or_->data)) == 1)
|
||||
auto or_list = static_cast<GList*> (_or_->data);
|
||||
if (or_list && !or_list->next)
|
||||
{
|
||||
q->terms = g_list_remove_link (static_cast<GList*>(q->terms), _or_);
|
||||
g_list_free_1 (_or_);
|
||||
@ -710,7 +711,7 @@ void qof_query_purge_terms (QofQuery *q, QofQueryParamList *param_list)
|
||||
}
|
||||
else
|
||||
{
|
||||
_or_->data = g_list_remove_link (static_cast<GList*>(_or_->data), _and_);
|
||||
_or_->data = g_list_remove_link (or_list, _and_);
|
||||
g_list_free_1 (_and_);
|
||||
_and_ = static_cast<GList*>(_or_->data);
|
||||
if (!_and_) break;
|
||||
@ -1137,7 +1138,7 @@ qof_query_merge(QofQuery *q1, QofQuery *q2, QofQueryOp op)
|
||||
* so that the first term added to an empty query doesn't screw up.
|
||||
*/
|
||||
if ((QOF_QUERY_AND == op) &&
|
||||
( (0 == qof_query_has_terms (q1)) || (0 == qof_query_has_terms (q2)) ))
|
||||
(q1->terms == NULL || q2->terms == NULL))
|
||||
{
|
||||
op = QOF_QUERY_OR;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user