diff options
author | Timm Bäder <mail@baedert.org> | 2016-01-06 10:58:08 +0100 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2016-01-27 22:17:28 -0500 |
commit | d7c628124cfb6768f6b5a0170f0872a42f5b213e (patch) | |
tree | e7362f38ee4f9652cd0b0070716aee21005613ab /gtk | |
parent | 4bf28f8a3bf0813e785d7ecea8f7e817baee4e08 (diff) | |
download | gtk+-d7c628124cfb6768f6b5a0170f0872a42f5b213e.tar.gz |
GtkListBox: Optimize _get_row_at_y a bit
Use g_sequence_lookup for a binary search over the rows.
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtklistbox.c | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c index 56d56b5fac..bb6249f772 100644 --- a/gtk/gtklistbox.c +++ b/gtk/gtklistbox.c @@ -670,6 +670,23 @@ gtk_list_box_get_row_at_index (GtkListBox *box, return NULL; } +static int +row_y_cmp_func (gconstpointer a, + gconstpointer b, + gpointer user_data) +{ + int y = GPOINTER_TO_INT (b); + GtkListBoxRowPrivate *row_priv = ROW_PRIV (a); + + + if (y < row_priv->y) + return 1; + else if (y >= row_priv->y + row_priv->height) + return -1; + + return 0; +} + /** * gtk_list_box_get_row_at_y: * @box: a #GtkListBox @@ -686,29 +703,19 @@ GtkListBoxRow * gtk_list_box_get_row_at_y (GtkListBox *box, gint y) { - GtkListBoxRow *row, *found_row; - GtkListBoxRowPrivate *row_priv; GSequenceIter *iter; g_return_val_if_fail (GTK_IS_LIST_BOX (box), NULL); - /* TODO: This should use g_sequence_search */ + iter = g_sequence_lookup (BOX_PRIV (box)->children, + GINT_TO_POINTER (y), + row_y_cmp_func, + NULL); - found_row = NULL; - for (iter = g_sequence_get_begin_iter (BOX_PRIV (box)->children); - !g_sequence_iter_is_end (iter); - iter = g_sequence_iter_next (iter)) - { - row = (GtkListBoxRow*) g_sequence_get (iter); - row_priv = ROW_PRIV (row); - if (y >= row_priv->y && y < (row_priv->y + row_priv->height)) - { - found_row = row; - break; - } - } + if (iter) + return GTK_LIST_BOX_ROW (g_sequence_get (iter)); - return found_row; + return NULL; } /** |