[gnu.emacs.bug] redisplay optimization for shared buffers

Duchier-Denys@cs.yale.edu (Denys Duchier) (01/18/90)

As long as I am on a roll... Also while hacking epoch I noticed I was
getting quite a bit of flickering when the current buffer appeared in
several windows. The problem is that DoDsp forces a complete redisplay
when the current buffer is shared. Here is a suggestion:

In function DoDsp (file xdisp.c):

replace line
  all_windows = RedoModes || buffer_shared > 1;
with
  all_windows = RedoModes;

Shortly thereafter, there is a conditional which handles the more
common cases and optimizes them. Modify the test as indicated. The
only difference is the additional conjunct buffer_shared <= 1:

  if (!all_windows && tlbufpos > 0 && NULL (w->redo_mode_line)
      /* Make sure recorded data applies to current buffer, etc */
      && this_line_buffer == bf_cur
      && bf_cur == XBUFFER (w->buffer)
      && NULL (w->force_start)
      /* Point must be on the line that we have info recorded about */
      && point >= tlbufpos
      && point <= bf_s1 + bf_s2 + 1 - tlendpos
      /* All text outside that line, including its final newline,
	 must be unchanged */
      && (XFASTINT (w->last_modified) >= bf_modified
	  || (
              /* The following conjunct is new.
	       * if we get here, the buffer has been modified,
	       * therefore we must punt if the buffer is shared
	       * and use the more expensive redisplay algorithm
	       */
	      buffer_shared <= 1 &&
	      beg_unchanged >= tlbufpos - 1
	      && bf_s1 >= tlbufpos - 1
	      && end_unchanged >= tlendpos
	      && bf_s2 >= tlendpos)))

Finally, if we fall through (ie. optimization is not applicable),
right after the line that follows the conditional:

  this_line_bufpos = 0;

add the following statement:

  all_windows |= buffer_shared > 1;

I believe this correctly optimizes the common case when the current
buffer is shared. If I am mistaken, please let me know. In practice,
the above trick seems to work.

--Denys