[gnc-sx-instance-model] prepend GList loops instead of append

This commit is contained in:
Christopher Lam 2022-08-08 12:59:34 +08:00
parent b94164e8ff
commit ad27be333e

View File

@ -451,7 +451,7 @@ static void
_build_list_from_hash_elts(gpointer key, gpointer value, gpointer user_data)
{
GList **list = (GList**)user_data;
*list = g_list_insert_sorted(*list, value, _compare_GncSxVariables);
*list = g_list_prepend (*list, value);
}
GList *
@ -459,13 +459,14 @@ gnc_sx_instance_get_variables(GncSxInstance *inst)
{
GList *vars = NULL;
g_hash_table_foreach(inst->variable_bindings, _build_list_from_hash_elts, &vars);
return vars;
return g_list_sort (vars, _compare_GncSxVariables);
}
static GncSxInstances*
_gnc_sx_gen_instances(gpointer *data, gpointer user_data)
{
GncSxInstances *instances = g_new0(GncSxInstances, 1);
GList *instlist = NULL;
SchedXaction *sx = (SchedXaction*)data;
const GDate *range_end = (const GDate*)user_data;
GDate creation_end, remind_end;
@ -493,8 +494,7 @@ _gnc_sx_gen_instances(gpointer *data, gpointer user_data)
seq_num = gnc_sx_get_instance_count(sx, postponed->data);
inst = gnc_sx_instance_new(instances, SX_INSTANCE_STATE_POSTPONED,
&inst_date, postponed->data, seq_num);
instances->instance_list =
g_list_append(instances->instance_list, inst);
instlist = g_list_prepend (instlist, inst);
gnc_sx_destroy_temporal_state(temporal_state);
temporal_state = gnc_sx_clone_temporal_state(postponed->data);
gnc_sx_incr_temporal_state(sx, temporal_state);
@ -512,7 +512,7 @@ _gnc_sx_gen_instances(gpointer *data, gpointer user_data)
seq_num = gnc_sx_get_instance_count(sx, temporal_state);
inst = gnc_sx_instance_new(instances, SX_INSTANCE_STATE_TO_CREATE,
&cur_date, temporal_state, seq_num);
instances->instance_list = g_list_append(instances->instance_list, inst);
instlist = g_list_prepend (instlist, inst);
gnc_sx_incr_temporal_state(sx, temporal_state);
cur_date = xaccSchedXactionGetNextInstance(sx, temporal_state);
}
@ -526,12 +526,13 @@ _gnc_sx_gen_instances(gpointer *data, gpointer user_data)
seq_num = gnc_sx_get_instance_count(sx, temporal_state);
inst = gnc_sx_instance_new(instances, SX_INSTANCE_STATE_REMINDER,
&cur_date, temporal_state, seq_num);
instances->instance_list = g_list_append(instances->instance_list,
inst);
instlist = g_list_prepend (instlist, inst);
gnc_sx_incr_temporal_state(sx, temporal_state);
cur_date = xaccSchedXactionGetNextInstance(sx, temporal_state);
}
instances->instance_list = g_list_reverse (instlist);
return instances;
}
@ -848,7 +849,7 @@ _find_unreferenced_vars(gchar *key,
!g_hash_table_lookup_extended(cb_pair->hash, key, NULL, NULL))
{
DEBUG("variable [%s] not found", key);
cb_pair->list = g_list_append(cb_pair->list, key);
cb_pair->list = g_list_prepend (cb_pair->list, key);
}
}
@ -928,7 +929,7 @@ gnc_sx_instance_model_update_sx_instances(GncSxInstanceModel *model, SchedXactio
removed_cb_data.hash = new_instances->variable_names;
removed_cb_data.list = NULL;
g_hash_table_foreach(existing->variable_names, (GHFunc)_find_unreferenced_vars, &removed_cb_data);
removed_var_names = removed_cb_data.list;
removed_var_names = g_list_reverse (removed_cb_data.list);
}
DEBUG("%d removed variables", g_list_length(removed_var_names));
@ -938,7 +939,7 @@ gnc_sx_instance_model_update_sx_instances(GncSxInstanceModel *model, SchedXactio
added_cb_data.hash = existing->variable_names;
added_cb_data.list = NULL;
g_hash_table_foreach(new_instances->variable_names, (GHFunc)_find_unreferenced_vars, &added_cb_data);
added_var_names = added_cb_data.list;
added_var_names = g_list_reverse (added_cb_data.list);
}
DEBUG("%d added variables", g_list_length(added_var_names));
@ -1556,7 +1557,7 @@ gnc_sx_instance_model_set_variable(GncSxInstanceModel *model,
static void
_list_from_hash_elts(gpointer key, gpointer value, GList **result_list)
{
*result_list = g_list_append(*result_list, value);
*result_list = g_list_prepend (*result_list, value);
}
GList*
@ -1584,7 +1585,7 @@ gnc_sx_instance_model_check_variables(GncSxInstanceModel *model)
GncSxVariableNeeded *need = g_new0(GncSxVariableNeeded, 1);
need->instance = inst;
need->variable = var;
rtn = g_list_append(rtn, need);
rtn = g_list_prepend (rtn, need);
}
}
g_list_free(var_list);