[gtk/wip/chergert/special-case-displaycache-y-is-zero] linedisplaycache: special case left-most binary search




commit def05ef87c43bd40ff18d964ac200ab5675a3ae2
Author: Christian Hergert <chergert redhat com>
Date:   Fri Aug 7 11:45:28 2020 -0700

    linedisplaycache: special case left-most binary search
    
    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.

 gtk/gtktextlinedisplaycache.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
---
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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]