constraints: Add some internal apis

Checking if a set is empty or a singleton can
be done more efficiently than determining its size.
This commit is contained in:
Matthias Clasen 2019-06-29 14:21:58 +00:00 committed by Emmanuele Bassi
parent a9dfca04e4
commit e3c4fb67ca
3 changed files with 20 additions and 2 deletions

View File

@ -505,6 +505,18 @@ gtk_constraint_variable_set_size (GtkConstraintVariableSet *set)
return g_sequence_get_length (set->set);
}
gboolean
gtk_constraint_variable_set_is_empty (GtkConstraintVariableSet *set)
{
return g_sequence_is_empty (set->set);
}
gboolean
gtk_constraint_variable_set_is_singleton (GtkConstraintVariableSet *set)
{
return g_sequence_iter_next (g_sequence_get_begin_iter (set->set)) == g_sequence_get_end_iter (set->set);
}
/*< private >
* GtkConstraintVariableSetIter:
*

View File

@ -94,6 +94,12 @@ gboolean
gtk_constraint_variable_set_remove (GtkConstraintVariableSet *set,
GtkConstraintVariable *variable);
gboolean
gtk_constraint_variable_set_is_empty (GtkConstraintVariableSet *set);
gboolean
gtk_constraint_variable_set_is_singleton (GtkConstraintVariableSet *set);
int
gtk_constraint_variable_set_size (GtkConstraintVariableSet *set);

View File

@ -1168,7 +1168,7 @@ gtk_constraint_solver_choose_subject (GtkConstraintSolver *self,
GtkConstraintVariableSet *cset = g_hash_table_lookup (self->columns, t_v);
if (cset == NULL ||
(gtk_constraint_variable_set_size (cset) == 1 &&
(gtk_constraint_variable_set_is_singleton (cset) &&
g_hash_table_contains (self->columns, self->objective)))
{
subject = t_v;
@ -1865,7 +1865,7 @@ gtk_constraint_solver_remove_constraint (GtkConstraintSolver *self,
if (exit_var == NULL)
{
if (gtk_constraint_variable_set_size (set) == 0)
if (gtk_constraint_variable_set_is_empty (set))
gtk_constraint_solver_remove_column (self, marker);
else
{