summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Hergert <chergert@redhat.com>2020-08-07 11:45:28 -0700
committerChristian Hergert <chergert@redhat.com>2020-08-07 11:45:28 -0700
commitdef05ef87c43bd40ff18d964ac200ab5675a3ae2 (patch)
treeed5b2e50f6f7031ca6576999fadc8d44ec4b8e57
parentcd0b9a2359275f320301705a4aaa0a8d1c4483ec (diff)
downloadgtk+-wip/chergert/special-case-displaycache-y-is-zero.tar.gz
linedisplaycache: special case left-most binary searchwip/chergert/special-case-displaycache-y-is-zero
If we have a y index of 0, we always want to look at the left-most position instead of wasting time on a binary search for edges. This is an extremely common case when loading or syntax highlighting a buffer such as from GtkSourceView.
-rw-r--r--gtk/gtktextlinedisplaycache.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/gtk/gtktextlinedisplaycache.c b/gtk/gtktextlinedisplaycache.c
index 91ce0d98e4..65835ba6bd 100644
--- a/gtk/gtktextlinedisplaycache.c
+++ b/gtk/gtktextlinedisplaycache.c
@@ -596,6 +596,18 @@ find_iter_at_at_y (GtkTextLineDisplayCache *cache,
g_assert (!g_sequence_iter_is_end (left));
g_assert (!g_sequence_iter_is_end (right));
+ /* One of the most common cases is y==0, so special case it. */
+ if (y == 0)
+ {
+ GtkTextLineDisplay *display = g_sequence_get (left);
+
+ g_assert (display != NULL);
+ g_assert (display->line != NULL);
+
+ if (_gtk_text_btree_find_line_top (btree, display->line, layout) <= 0)
+ return left;
+ }
+
for (;;)
{
GtkTextLineDisplay *display;