diff options
author | Gregory Heytings <gregory@heytings.org> | 2022-07-19 21:21:40 +0000 |
---|---|---|
committer | Gregory Heytings <gregory@heytings.org> | 2022-07-19 23:34:09 +0200 |
commit | 7c0fc853649c7e203814295de32357cfd6a336a9 (patch) | |
tree | 9234ae81bb18ce6403c4859b37b8e39583ccc3bf /src | |
parent | c6bee1707523549ce02eadb506f54e9089ea1a3f (diff) | |
download | emacs-7c0fc853649c7e203814295de32357cfd6a336a9.tar.gz |
Simplified and improved heuristic for long lines detection.
* src/lisp.h (modiff_incr): Add a parameter to 'modiff_incr' to record
the extent of the modification.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, adjust_after_replace, replace_range,
replace_range_2, del_range_2, modify_text): Add an argument to each
call to 'modiff_incr'.
* src/textprop.c (modify_text_properties): Add an argument to the call
to 'modiff_incr'.
* src/buffer.c (Frestore_buffer_modified_p, Fbuffer_swap_text,
modify_overlay): Add an argument to each call to 'modiff_incr'.
* src/xdisp.c (redisplay_window): Use the improved version of 'MODIFF'
for the heuristic.
Diffstat (limited to 'src')
-rw-r--r-- | src/buffer.c | 16 | ||||
-rw-r--r-- | src/insdel.c | 18 | ||||
-rw-r--r-- | src/lisp.h | 7 | ||||
-rw-r--r-- | src/textprop.c | 2 | ||||
-rw-r--r-- | src/xdisp.c | 2 |
5 files changed, 23 insertions, 22 deletions
diff --git a/src/buffer.c b/src/buffer.c index a777668e44b..edd85d8ef63 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1501,7 +1501,7 @@ state of the current buffer. Use with care. */) decrease SAVE_MODIFF and auto_save_modified or increase MODIFF. */ if (SAVE_MODIFF >= MODIFF) - SAVE_MODIFF = modiff_incr (&MODIFF); + SAVE_MODIFF = modiff_incr (&MODIFF, 1); if (EQ (flag, Qautosaved)) BUF_AUTOSAVE_MODIFF (b) = MODIFF; } @@ -2466,12 +2466,12 @@ results, see Info node `(elisp)Swapping Text'. */) bset_point_before_scroll (current_buffer, Qnil); bset_point_before_scroll (other_buffer, Qnil); - modiff_incr (¤t_buffer->text->modiff); - modiff_incr (&other_buffer->text->modiff); - modiff_incr (¤t_buffer->text->chars_modiff); - modiff_incr (&other_buffer->text->chars_modiff); - modiff_incr (¤t_buffer->text->overlay_modiff); - modiff_incr (&other_buffer->text->overlay_modiff); + modiff_incr (¤t_buffer->text->modiff, 1); + modiff_incr (&other_buffer->text->modiff, 1); + modiff_incr (¤t_buffer->text->chars_modiff, 1); + modiff_incr (&other_buffer->text->chars_modiff, 1); + modiff_incr (¤t_buffer->text->overlay_modiff, 1); + modiff_incr (&other_buffer->text->overlay_modiff, 1); current_buffer->text->beg_unchanged = current_buffer->text->gpt; current_buffer->text->end_unchanged = current_buffer->text->gpt; other_buffer->text->beg_unchanged = other_buffer->text->gpt; @@ -4010,7 +4010,7 @@ modify_overlay (struct buffer *buf, ptrdiff_t start, ptrdiff_t end) bset_redisplay (buf); - modiff_incr (&BUF_OVERLAY_MODIFF (buf)); + modiff_incr (&BUF_OVERLAY_MODIFF (buf), end - start); } /* Remove OVERLAY from LIST. */ diff --git a/src/insdel.c b/src/insdel.c index 6f180ac5800..309ca728a4c 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -909,7 +909,7 @@ insert_1_both (const char *string, the insertion. This, together with recording the insertion, will add up to the right stuff in the undo list. */ record_insert (PT, nchars); - modiff_incr (&MODIFF); + modiff_incr (&MODIFF, nchars); CHARS_MODIFF = MODIFF; memcpy (GPT_ADDR, string, nbytes); @@ -1037,7 +1037,7 @@ insert_from_string_1 (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, #endif record_insert (PT, nchars); - modiff_incr (&MODIFF); + modiff_incr (&MODIFF, nchars); CHARS_MODIFF = MODIFF; GAP_SIZE -= outgoing_nbytes; @@ -1122,7 +1122,7 @@ insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail) of this dance. */ invalidate_buffer_caches (current_buffer, GPT, GPT); record_insert (GPT, nchars); - modiff_incr (&MODIFF); + modiff_incr (&MODIFF, nchars); insert_from_gap_1 (nchars, nbytes, text_at_gap_tail); @@ -1250,7 +1250,7 @@ insert_from_buffer_1 (struct buffer *buf, #endif record_insert (PT, nchars); - modiff_incr (&MODIFF); + modiff_incr (&MODIFF, nchars); CHARS_MODIFF = MODIFF; GAP_SIZE -= outgoing_nbytes; @@ -1351,7 +1351,7 @@ adjust_after_replace (ptrdiff_t from, ptrdiff_t from_byte, if (len == 0) evaporate_overlays (from); - modiff_incr (&MODIFF); + modiff_incr (&MODIFF, nchars_del + len); CHARS_MODIFF = MODIFF; } @@ -1546,7 +1546,7 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new, check_markers (); - modiff_incr (&MODIFF); + modiff_incr (&MODIFF, nchars_del + inschars); CHARS_MODIFF = MODIFF; if (adjust_match_data) @@ -1680,7 +1680,7 @@ replace_range_2 (ptrdiff_t from, ptrdiff_t from_byte, check_markers (); - modiff_incr (&MODIFF); + modiff_incr (&MODIFF, nchars_del + inschars); CHARS_MODIFF = MODIFF; } @@ -1855,7 +1855,7 @@ del_range_2 (ptrdiff_t from, ptrdiff_t from_byte, at the end of the text before the gap. */ adjust_markers_for_delete (from, from_byte, to, to_byte); - modiff_incr (&MODIFF); + modiff_incr (&MODIFF, nchars_del); CHARS_MODIFF = MODIFF; /* Relocate point as if it were a marker. */ @@ -1909,7 +1909,7 @@ modify_text (ptrdiff_t start, ptrdiff_t end) BUF_COMPUTE_UNCHANGED (current_buffer, start - 1, end); if (MODIFF <= SAVE_MODIFF) record_first_change (); - modiff_incr (&MODIFF); + modiff_incr (&MODIFF, end - start); CHARS_MODIFF = MODIFF; bset_point_before_scroll (current_buffer, Qnil); diff --git a/src/lisp.h b/src/lisp.h index 5045d49e1b6..6e8c2f3a2f9 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3911,10 +3911,11 @@ integer_to_uintmax (Lisp_Object num, uintmax_t *n) typedef intmax_t modiff_count; INLINE modiff_count -modiff_incr (modiff_count *a) +modiff_incr (modiff_count *a, ptrdiff_t len) { - modiff_count a0 = *a; - bool modiff_overflow = INT_ADD_WRAPV (a0, 1, a); + modiff_count a0 = *a; int incr = len ? 1 : 0; + while (len >>= 1) incr++; + bool modiff_overflow = INT_ADD_WRAPV (a0, incr, a); eassert (!modiff_overflow && *a >> 30 >> 30 == 0); return a0; } diff --git a/src/textprop.c b/src/textprop.c index 96d07b44be8..c91a2b729c6 100644 --- a/src/textprop.c +++ b/src/textprop.c @@ -88,7 +88,7 @@ modify_text_properties (Lisp_Object buffer, Lisp_Object start, Lisp_Object end) BUF_COMPUTE_UNCHANGED (buf, b - 1, e); if (MODIFF <= SAVE_MODIFF) record_first_change (); - modiff_incr (&MODIFF); + modiff_incr (&MODIFF, 1); bset_point_before_scroll (current_buffer, Qnil); diff --git a/src/xdisp.c b/src/xdisp.c index ec01375e1f8..b1c492fab3a 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) + && MODIFF - UNCHANGED_MODIFIED > 4) { ptrdiff_t cur, next, found, max = 0; for (cur = 1; cur < Z; cur = next) |