Collect sequences of printable ASCII characters and process them

together instead of handling them one by one. This is significantly
faster. Sequences are terminated when we reach the end of the line, fill
the internal buffer, or a different character is seen by the input
parser (an escape sequence, or UTF-8).

Rather than writing collected sequences out immediately, hold them until
it is necessary (another screen modification, or we consume all
available data). This means we can discard changes that would have no
effect (for example, lines that would just be scrolled off the screen or
cleared). This reduces the total amount of data we write out to the
terminal - not important for fast terminals, but a big help with slow
(like xterm).
This commit is contained in:
nicm
2017-02-08 16:45:18 +00:00
parent d4b006b9fa
commit 13a0b6bb3f
7 changed files with 319 additions and 187 deletions

12
input.c
View File

@ -895,6 +895,16 @@ input_parse(struct window_pane *wp)
fatalx("no transition from state");
}
/*
* Any state except print stops the current collection. This is
* an optimization to avoid checking if the attributes have
* changed for every character. It will stop unnecessarily for
* sequences that don't make a terminal change, but they should
* be the minority.
*/
if (itr->handler != input_print)
screen_write_collect_end(&ictx->ctx);
/*
* Execute the handler, if any. Don't switch state if it
* returns non-zero.
@ -1020,7 +1030,7 @@ input_print(struct input_ctx *ictx)
ictx->cell.cell.attr &= ~GRID_ATTR_CHARSET;
utf8_set(&ictx->cell.cell.data, ictx->ch);
screen_write_cell(&ictx->ctx, &ictx->cell.cell);
screen_write_collect_add(&ictx->ctx, &ictx->cell.cell);
ictx->cell.cell.attr &= ~GRID_ATTR_CHARSET;