- }
- if (!cleared && tt.tt_clreol != 0
- && ncleared > wwncol - scol - nblank
- && nblank > (wwncol - scol) / 2) {
- /* clear to the end */
- (*tt.tt_move)(srow, scol);
- (*tt.tt_clreol)();
- s = &wwos[srow][scol];
- for (i = wwncol - scol; --i >= 0;)
- s++->c_w = ' ';
+ }
+ } else {
+ register union ww_char *s;
+ register char *smap, *win;
+ int ntouched = 0;
+ int gain = 0;
+
+ i = col;
+ smap = &wwsmap[row][i];
+ s = wwns[row];
+ win = w->ww_win[row];
+ for (; i < w->ww_i.r; i++) {
+ if (*smap++ != w->ww_index) {
+ if (s[i].c_w != ' ')
+ gain--;
+ } else if (win[i] == 0) {
+ if (s[i].c_w != ' ') {
+ gain++;
+ ntouched++;
+ s[i].c_w = ' ';
+ }
+ } else {
+ short c = ' ' | win[i] << WWC_MSHIFT;
+ if (s[i].c_w == c)
+ gain--;
+ else {
+ s[i].c_w = c;
+ ntouched++;
+ }
+ }
+ }
+ s += i;
+ for (i = wwncol - i; --i >= 0;)
+ if (s++->c_w != ' ')
+ gain--;
+ if (ntouched > 0)
+ wwtouched[row] |= WWU_TOUCHED;
+ /*
+ * Can/should we use clear eol?
+ */
+ if (tt.tt_clreol != 0 && gain > 4) {
+ /* clear to the end */
+ (*tt.tt_move)(row, col);
+ (*tt.tt_clreol)();
+ s = &wwos[row][col];
+ for (i = wwncol - col; --i >= 0;)
+ s++->c_w = ' ';
+ }