aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGerd Möllmann2022-09-11 11:42:18 +0200
committerGerd Möllmann2022-09-17 15:33:10 +0200
commitcbac94b4aeecdf57e2a1f3e95e27ec76505ae964 (patch)
treed9f6c4bc4a5313849d57aa14bbb57e59f6564ff2 /src
parent5bf8f9cc0d2fb12071301f50f9b85640d240a1fc (diff)
downloademacs-cbac94b4aeecdf57e2a1f3e95e27ec76505ae964.tar.gz
emacs-cbac94b4aeecdf57e2a1f3e95e27ec76505ae964.zip
Optimize tty display updates (bug#57727)
* src/dispnew.c (update_frame_1): Don'f flush if tty's output_buffer_size is non-zero. * src/sysdep.c (init_sys_modes): Setvbuf depending on the tty's output_buffer_size. * src/term.c (Ftty__set_output_buffer_size, Ftty__output_buffer_size): Low-level interface for setting and retrieving a tty's output buffer size. (syms_of_term): Defsubr the new functions. * src/termchar.h (struct tty_display_info): New member output_buffer_size. * stc/NEWS: Describe the change.
Diffstat (limited to 'src')
-rw-r--r--src/dispnew.c4
-rw-r--r--src/sysdep.c5
-rw-r--r--src/term.c38
-rw-r--r--src/termchar.h5
4 files changed, 50 insertions, 2 deletions
diff --git a/src/dispnew.c b/src/dispnew.c
index 8932f103f1f..b786f0f1ba4 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -4929,7 +4929,9 @@ update_frame_1 (struct frame *f, bool force_p, bool inhibit_id_p,
4929 { 4929 {
4930 if (MATRIX_ROW_ENABLED_P (desired_matrix, i)) 4930 if (MATRIX_ROW_ENABLED_P (desired_matrix, i))
4931 { 4931 {
4932 if (FRAME_TERMCAP_P (f)) 4932 /* Note that output_buffer_size being 0 means that we want the
4933 old default behavior of flushing output every now and then. */
4934 if (FRAME_TERMCAP_P (f) && FRAME_TTY (f)->output_buffer_size == 0)
4933 { 4935 {
4934 /* Flush out every so many lines. 4936 /* Flush out every so many lines.
4935 Also flush out if likely to have more than 1k buffered 4937 Also flush out if likely to have more than 1k buffered
diff --git a/src/sysdep.c b/src/sysdep.c
index efd9638b07a..abb385d1388 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1304,7 +1304,10 @@ init_sys_modes (struct tty_display_info *tty_out)
1304 } 1304 }
1305#endif /* F_GETOWN */ 1305#endif /* F_GETOWN */
1306 1306
1307 setvbuf (tty_out->output, NULL, _IOFBF, BUFSIZ); 1307 const size_t buffer_size = (tty_out->output_buffer_size
1308 ? tty_out->output_buffer_size
1309 : BUFSIZ);
1310 setvbuf (tty_out->output, NULL, _IOFBF, buffer_size);
1308 1311
1309 if (tty_out->terminal->set_terminal_modes_hook) 1312 if (tty_out->terminal->set_terminal_modes_hook)
1310 tty_out->terminal->set_terminal_modes_hook (tty_out->terminal); 1313 tty_out->terminal->set_terminal_modes_hook (tty_out->terminal);
diff --git a/src/term.c b/src/term.c
index 2e43d89232f..231324d002a 100644
--- a/src/term.c
+++ b/src/term.c
@@ -2400,6 +2400,42 @@ frame's terminal). */)
2400 return Qnil; 2400 return Qnil;
2401} 2401}
2402 2402
2403DEFUN ("tty--set-output-buffer-size", Ftty__set_output_buffer_size,
2404 Stty__set_output_buffer_size, 1, 2, 0, doc:
2405 /* Set the output buffer size for a TTY.
2406
2407SIZE zero means use the system's default value. If SIZE is
2408non-zero, this also avoids flushing the output stream.
2409
2410TTY may be a terminal object, a frame, or nil (meaning the selected
2411frame's terminal).
2412
2413This function temporarily suspends and resumes the terminal
2414device. */)
2415 (Lisp_Object size, Lisp_Object tty)
2416{
2417 if (!TYPE_RANGED_FIXNUMP (size_t, size))
2418 error ("Invalid output buffer size");
2419 Fsuspend_tty (tty);
2420 struct terminal *terminal = decode_tty_terminal (tty);
2421 terminal->display_info.tty->output_buffer_size = XFIXNUM (size);
2422 return Fresume_tty (tty);
2423}
2424
2425DEFUN ("tty--output-buffer-size", Ftty__output_buffer_size,
2426 Stty__output_buffer_size, 0, 1, 0, doc:
2427 /* Return the output buffer size of TTY.
2428
2429TTY may be a terminal object, a frame, or nil (meaning the selected
2430frame's terminal).
2431
2432A value of zero means TTY uses the system's default value. */)
2433 (Lisp_Object tty)
2434{
2435 struct terminal *terminal = decode_tty_terminal (tty);
2436 return make_fixnum (terminal->display_info.tty->output_buffer_size);
2437}
2438
2403 2439
2404/*********************************************************************** 2440/***********************************************************************
2405 Mouse 2441 Mouse
@@ -4556,6 +4592,8 @@ trigger redisplay. */);
4556 defsubr (&Stty_top_frame); 4592 defsubr (&Stty_top_frame);
4557 defsubr (&Ssuspend_tty); 4593 defsubr (&Ssuspend_tty);
4558 defsubr (&Sresume_tty); 4594 defsubr (&Sresume_tty);
4595 defsubr (&Stty__set_output_buffer_size);
4596 defsubr (&Stty__output_buffer_size);
4559#ifdef HAVE_GPM 4597#ifdef HAVE_GPM
4560 defsubr (&Sgpm_mouse_start); 4598 defsubr (&Sgpm_mouse_start);
4561 defsubr (&Sgpm_mouse_stop); 4599 defsubr (&Sgpm_mouse_stop);
diff --git a/src/termchar.h b/src/termchar.h
index 49560dbc2ad..0f172464113 100644
--- a/src/termchar.h
+++ b/src/termchar.h
@@ -53,6 +53,11 @@ struct tty_display_info
53 FILE *output; /* The stream to be used for terminal output. 53 FILE *output; /* The stream to be used for terminal output.
54 NULL if the terminal is suspended. */ 54 NULL if the terminal is suspended. */
55 55
56 /* Size of output buffer. A value of zero means use the default of
57 BUFIZE. If non-zero, also minimize writes to the tty by avoiding
58 calls to flush. */
59 size_t output_buffer_size;
60
56 FILE *termscript; /* If nonzero, send all terminal output 61 FILE *termscript; /* If nonzero, send all terminal output
57 characters to this stream also. */ 62 characters to this stream also. */
58 63