+ /*
+ * Find how many lines from the top of the screen are unchanged.
+ */
+ for (top = 0; top < win->maxy; top++)
+ if (win->lines[top]->flags & __FORCEPAINT ||
+ win->lines[top]->hash != curscr->lines[top]->hash
+ || memcmp(win->lines[top]->line,
+ curscr->lines[top]->line,
+ win->maxx * __LDATASIZE) != 0)
+ break;
+ else
+ win->lines[top]->flags &= ~__ISDIRTY;
+ /*
+ * Find how many lines from bottom of screen are unchanged.
+ */
+ for (bot = win->maxy - 1; bot >= 0; bot--)
+ if (win->lines[bot]->flags & __FORCEPAINT ||
+ win->lines[bot]->hash != curscr->lines[bot]->hash
+ || memcmp(win->lines[bot]->line,
+ curscr->lines[bot]->line,
+ win->maxx * __LDATASIZE) != 0)
+ break;
+ else
+ win->lines[bot]->flags &= ~__ISDIRTY;
+
+#ifdef NO_JERKINESS
+ /*
+ * If we have a bottom unchanged region return. Scrolling the
+ * bottom region up and then back down causes a screen jitter.
+ * This will increase the number of characters sent to the screen
+ * but it looks better.
+ */
+ if (bot < win->maxy - 1)
+ return;
+#endif /* NO_JERKINESS */
+
+ /*
+ * Search for the largest block of text not changed.
+ * Invariants of the loop:
+ * - Startw is the index of the beginning of the examined block in win.
+ * - Starts is the index of the beginning of the examined block in
+ * curscr.
+ * - Curs is the index of one past the end of the exmined block in win.
+ * - Curw is the index of one past the end of the exmined block in
+ * curscr.
+ * - bsize is the current size of the examined block.
+ */
+ for (bsize = bot - top; bsize >= THRESH; bsize--) {
+ for (startw = top; startw <= bot - bsize; startw++)
+ for (starts = top; starts <= bot - bsize;