emacs-diffs
[Top][All Lists]
Advanced

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

feature/fix-the-long-lines-display-bug 1ff69cc744: Improve the heuristic


From: Gregory Heytings
Subject: feature/fix-the-long-lines-display-bug 1ff69cc744: Improve the heuristic for long lines detection.
Date: Mon, 18 Jul 2022 11:55:19 -0400 (EDT)

branch: feature/fix-the-long-lines-display-bug
commit 1ff69cc744eaa704afc1ff81242d41a6c09439fe
Author: Gregory Heytings <gregory@heytings.org>
Commit: Gregory Heytings <gregory@heytings.org>

    Improve the heuristic for long lines detection.
    
    * src/buffer.h (struct buffer_text): New 'unchanged_size' field.
    (BUF_UNCHANGED_SIZE): New macro to access the field.
    
    * src/buffer.c (Fget_buffer_create): Initialize the field.
    (Fbuffer_swap_text): Handle it.
    
    * src/xdisp.c (mark_window_display_accurate_1): Set the field.
    (redisplay_window): Use the field for long lines detection.
---
 src/buffer.c | 6 ++++++
 src/buffer.h | 6 ++++++
 src/xdisp.c  | 3 ++-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/buffer.c b/src/buffer.c
index a777668e44..9a463363b9 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -599,6 +599,7 @@ even if it is dead.  The return value is never nil.  */)
   BUF_OVERLAY_UNCHANGED_MODIFIED (b) = 1;
   BUF_END_UNCHANGED (b) = 0;
   BUF_BEG_UNCHANGED (b) = 0;
+  BUF_UNCHANGED_SIZE (b) = 0;
   *(BUF_GPT_ADDR (b)) = *(BUF_Z_ADDR (b)) = 0; /* Put an anchor '\0'.  */
   b->text->inhibit_shrinking = false;
   b->text->redisplay = false;
@@ -2476,6 +2477,11 @@ results, see Info node `(elisp)Swapping Text'.  */)
   current_buffer->text->end_unchanged = current_buffer->text->gpt;
   other_buffer->text->beg_unchanged = other_buffer->text->gpt;
   other_buffer->text->end_unchanged = other_buffer->text->gpt;
+  {
+    ptrdiff_t tmp = current_buffer->text->unchanged_size;
+    current_buffer->text->unchanged_size = other_buffer->text->unchanged_size;
+    other_buffer->text->unchanged_size = tmp;
+  }
   {
     struct Lisp_Marker *m;
     for (m = BUF_MARKERS (current_buffer); m; m = m->next)
diff --git a/src/buffer.h b/src/buffer.h
index 09daa29992..c2dca0a10c 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -144,6 +144,9 @@ enum { BEG = 1, BEG_BYTE = BEG };
 #define BUF_UNCHANGED_MODIFIED(buf) \
   ((buf)->text->unchanged_modified)
 
+#define BUF_UNCHANGED_SIZE(buf) \
+  ((buf)->text->unchanged_size)
+
 #define BUF_OVERLAY_UNCHANGED_MODIFIED(buf) \
   ((buf)->text->overlay_unchanged_modified)
 #define BUF_BEG_UNCHANGED(buf) ((buf)->text->beg_unchanged)
@@ -267,6 +270,9 @@ struct buffer_text
        end_unchanged contain no useful information.  */
     modiff_count overlay_unchanged_modified;
 
+    /* Buffer size as of last redisplay that finished.  */
+    ptrdiff_t unchanged_size;
+
     /* Properties of this buffer's text.  */
     INTERVAL intervals;
 
diff --git a/src/xdisp.c b/src/xdisp.c
index 572ad2b854..375158a520 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -17074,6 +17074,7 @@ mark_window_display_accurate_1 (struct window *w, bool 
accurate_p)
       BUF_OVERLAY_UNCHANGED_MODIFIED (b) = BUF_OVERLAY_MODIFF (b);
       BUF_BEG_UNCHANGED (b) = BUF_GPT (b) - BUF_BEG (b);
       BUF_END_UNCHANGED (b) = BUF_Z (b) - BUF_GPT (b);
+      BUF_UNCHANGED_SIZE (b) = BUF_Z (b) - BUF_BEG (b);
 
       w->current_matrix->buffer = b;
       w->current_matrix->begv = BUF_BEGV (b);
@@ -19279,7 +19280,7 @@ redisplay_window (Lisp_Object window, bool 
just_this_one_p)
   /* Check whether the buffer to be displayed contains long lines.  */
   if (!NILP (Vlong_line_threshold)
       && !current_buffer->long_line_optimizations_p
-      && MODIFF != UNCHANGED_MODIFIED)
+      && Z - BEG - BUF_UNCHANGED_SIZE (current_buffer) <= 1)
     {
       ptrdiff_t cur, next, found, max = 0;
       for (cur = 1; cur < Z; cur = next)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]