summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/input.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2017-02-08 16:45:18 +0000
committernicm <nicm@openbsd.org>2017-02-08 16:45:18 +0000
commit8248eab75e35e591957242570e83a0767175134b (patch)
treef62c5aeea7efbb56878a5f4883413d4b582b7391 /usr.bin/tmux/input.c
parentAbort transactions with non-retriable error when device is stopped (diff)
downloadwireguard-openbsd-8248eab75e35e591957242570e83a0767175134b.tar.xz
wireguard-openbsd-8248eab75e35e591957242570e83a0767175134b.zip
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).
Diffstat (limited to 'usr.bin/tmux/input.c')
-rw-r--r--usr.bin/tmux/input.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/usr.bin/tmux/input.c b/usr.bin/tmux/input.c
index 2986cae7603..f26a73ad525 100644
--- a/usr.bin/tmux/input.c
+++ b/usr.bin/tmux/input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: input.c,v 1.113 2017/02/08 15:49:29 nicm Exp $ */
+/* $OpenBSD: input.c,v 1.114 2017/02/08 16:45:18 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -896,6 +896,16 @@ input_parse(struct window_pane *wp)
}
/*
+ * 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;