GtkLabel: Don't manually iterate over link list

There are various functions to access links based on their index for
a11y. We can spare quite a few lines of code by just using
g_list_nth_data instead of iterating over the list ourselves.

https://bugzilla.gnome.org/show_bug.cgi?id=765496
This commit is contained in:
Timm Bäder 2016-04-24 10:32:55 +02:00 committed by Matthias Clasen
parent f165bbda57
commit be5a105f2e

View File

@ -7048,19 +7048,13 @@ _gtk_label_get_link_uri (GtkLabel *label,
gint idx)
{
GtkLabelPrivate *priv = label->priv;
gint i;
GList *l;
GtkLabelLink *link;
if (priv->select_info)
for (l = priv->select_info->links, i = 0; l; l = l->next, i++)
{
if (i == idx)
{
link = l->data;
return link->uri;
}
}
{
GtkLabelLink *link = g_list_nth_data (priv->select_info->links, idx);
if (link)
return link->uri;
}
return NULL;
}
@ -7113,24 +7107,18 @@ _gtk_label_get_link_at (GtkLabel *label,
}
void
_gtk_label_activate_link (GtkLabel *label,
_gtk_label_activate_link (GtkLabel *label,
gint idx)
{
GtkLabelPrivate *priv = label->priv;
gint i;
GList *l;
GtkLabelLink *link;
if (priv->select_info)
for (l = priv->select_info->links, i = 0; l; l = l->next, i++)
{
if (i == idx)
{
link = l->data;
emit_activate_link (label, link);
return;
}
}
{
GtkLabelLink *link = g_list_nth_data (priv->select_info->links, idx);
if (link)
emit_activate_link (label, link);
}
}
gboolean
@ -7138,19 +7126,12 @@ _gtk_label_get_link_visited (GtkLabel *label,
gint idx)
{
GtkLabelPrivate *priv = label->priv;
gint i;
GList *l;
GtkLabelLink *link;
if (priv->select_info)
for (l = priv->select_info->links, i = 0; l; l = l->next, i++)
{
if (i == idx)
{
link = l->data;
return link->visited;
}
}
{
GtkLabelLink *link = g_list_nth_data (priv->select_info->links, idx);
return link ? link->visited : FALSE;
}
return FALSE;
}