size group: streamline iteration slightly

Instead of handling the horizontal and vertical peers separately
(and often, duplicatively), collect all peers in one go. At the
same time, avoid creating and destroying hash tables more often
than necessary.
This commit is contained in:
Matthias Clasen 2015-09-20 00:50:27 -04:00
parent ac72a9cedc
commit e0be076652

View File

@ -155,7 +155,7 @@ static void
add_widget_to_closure (GHashTable *widgets,
GHashTable *groups,
GtkWidget *widget,
GtkOrientation orientation)
gint orientation)
{
GSList *tmp_groups, *tmp_widgets;
gboolean hidden;
@ -177,7 +177,7 @@ add_widget_to_closure (GHashTable *widgets,
if (tmp_priv->ignore_hidden && hidden)
continue;
if (!(tmp_priv->mode & (1 << orientation)))
if (orientation >= 0 && !(tmp_priv->mode & (1 << orientation)))
continue;
g_hash_table_add (groups, tmp_group);
@ -193,8 +193,8 @@ _gtk_size_group_get_widget_peers (GtkWidget *for_widget,
{
GHashTable *widgets, *groups;
widgets = g_hash_table_new (g_direct_hash, g_direct_equal);
groups = g_hash_table_new (g_direct_hash, g_direct_equal);
widgets = g_hash_table_new (NULL, NULL);
groups = g_hash_table_new (NULL, NULL);
add_widget_to_closure (widgets, groups, for_widget, orientation);
@ -231,12 +231,18 @@ queue_resize_on_widget (GtkWidget *widget,
gboolean check_siblings,
GtkQueueResizeFlags flags)
{
GtkWidget *parent = widget;
GHashTable *widgets;
GHashTable *groups;
GtkWidget *parent;
widgets = g_hash_table_new (NULL, NULL);
groups = g_hash_table_new (NULL, NULL);
parent = widget;
while (parent)
{
GSList *widget_groups;
GHashTable *widgets;
GHashTableIter iter;
gpointer current;
@ -257,7 +263,9 @@ queue_resize_on_widget (GtkWidget *widget,
continue;
}
widgets = _gtk_size_group_get_widget_peers (parent, GTK_ORIENTATION_HORIZONTAL);
g_hash_table_remove_all (widgets);
g_hash_table_remove_all (groups);
add_widget_to_closure (widgets, groups, parent, -1);
g_hash_table_iter_init (&iter, widgets);
while (g_hash_table_iter_next (&iter, &current, NULL))
@ -275,30 +283,11 @@ queue_resize_on_widget (GtkWidget *widget,
queue_resize_on_widget (current, FALSE, flags);
}
g_hash_table_destroy (widgets);
widgets = _gtk_size_group_get_widget_peers (parent, GTK_ORIENTATION_VERTICAL);
g_hash_table_iter_init (&iter, widgets);
while (g_hash_table_iter_next (&iter, &current, NULL))
{
if (current == parent)
{
if (widget == parent)
real_queue_resize (parent, flags);
}
else if (current == widget)
{
g_warning ("A container and its child are part of this SizeGroup");
}
else
queue_resize_on_widget (current, FALSE, flags);
}
g_hash_table_destroy (widgets);
parent = _gtk_widget_get_parent (parent);
}
g_hash_table_destroy (widgets);
g_hash_table_destroy (groups);
}
static void