From: Gregory Heytings Date: Wed, 20 Jul 2022 17:12:23 +0000 (+0000) Subject: Further tweaks to long lines handling. X-Git-Tag: emacs-29.0.90~1447^2~821^2~1 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c7eef61eee179d127d4edeb828c723f4dee530b4;p=emacs.git Further tweaks to long lines handling. * src/xdisp.c (redisplay_window): Increase the threshold above which long lines detection is performed in the buffer. This should avoid triggering that detection for most simple editing operations. * src/lisp.h (modiff_incr): Explain why the counter is incremented logarithmically. * src/buffer.h (struct buffer_text): Adapt the comment about the 'modiff' field accordingly. * src/buffer.c (modify_overlay): Increase the counter by 1 instead of the size of the buffer section on which the overlay is placed. * etc/NEWS: Small improvement. --- diff --git a/etc/NEWS b/etc/NEWS index 45efe2a08e6..2217960381d 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -330,9 +330,9 @@ The display of long lines has been optimized, and Emacs no longer chokes when a buffer on display contains long lines. If you still experience slowdowns while editing files with long lines, this is either due to font locking, which you can turn off with M-x -font-lock-mode, or to the current major mode or one of the enabled -minor modes, in which case you should open the the file with M-x -find-file-literally instead of C-x C-f. The variable +font-lock-mode or C-u C-x x f, or to the current major mode or one of +the enabled minor modes, in which case you should open the the file +with M-x find-file-literally instead of C-x C-f. The variable 'long-line-threshold' controls whether and when these display optimizations are used. diff --git a/src/buffer.c b/src/buffer.c index edd85d8ef63..d8964180cff 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -4010,7 +4010,7 @@ modify_overlay (struct buffer *buf, ptrdiff_t start, ptrdiff_t end) bset_redisplay (buf); - modiff_incr (&BUF_OVERLAY_MODIFF (buf), end - start); + modiff_incr (&BUF_OVERLAY_MODIFF (buf), 1); } /* Remove OVERLAY from LIST. */ diff --git a/src/buffer.h b/src/buffer.h index 09daa29992a..47b4bdf749b 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -237,9 +237,10 @@ struct buffer_text ptrdiff_t z_byte; /* Byte pos of end of buffer. */ ptrdiff_t gap_size; /* Size of buffer's gap. */ modiff_count modiff; /* This counts buffer-modification events - for this buffer. It is incremented for - each such event, and never otherwise - changed. */ + for this buffer. It is increased + logarithmically to the extent of the + modification for each such event, + and never otherwise changed. */ modiff_count chars_modiff; /* This is modified with character change events for this buffer. It is set to modiff for each such event, and never diff --git a/src/lisp.h b/src/lisp.h index 6e8c2f3a2f9..dabf013d531 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3914,6 +3914,9 @@ INLINE modiff_count modiff_incr (modiff_count *a, ptrdiff_t len) { modiff_count a0 = *a; int incr = len ? 1 : 0; + /* Increase the counter more for a large modification and less for a + small modification. Increase it logarithmically to avoid + increasing it too much. */ while (len >>= 1) incr++; bool modiff_overflow = INT_ADD_WRAPV (a0, incr, a); eassert (!modiff_overflow && *a >> 30 >> 30 == 0); diff --git a/src/xdisp.c b/src/xdisp.c index b1c492fab3a..4701e2b2459 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -19293,7 +19293,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 > 4) + && MODIFF - UNCHANGED_MODIFIED > 8) { ptrdiff_t cur, next, found, max = 0; for (cur = 1; cur < Z; cur = next)