aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2024-04-06 17:36:24 +0300
committerAvi Halachmi (:avih) <avihpit@yahoo.com>2024-04-06 23:56:58 +0300
commit758a72f55360a1f3a5400aeca29bc2ea0647bad1 (patch)
tree9b49a9c30dc1ac476ddb8d19955a476ba0a60540
parent2b8bc1b4760d8ecb4fdcdd79923d29d0ab20b908 (diff)
downloadbusybox-w32-758a72f55360a1f3a5400aeca29bc2ea0647bad1.tar.gz
busybox-w32-758a72f55360a1f3a5400aeca29bc2ea0647bad1.tar.bz2
busybox-w32-758a72f55360a1f3a5400aeca29bc2ea0647bad1.zip
win32: ascii-optimize winansi_fputc, winansi_putchar
Other winansi IO wrappers, like winansi_fputs, optimize by calling the libc API directly if no special handling is needed, e.g. if the input is fully ASCII and without escape sequences - without converting the output codepage or interpreting escapes. Now the fputc and putchar wrappers do that as well. And as a simplification, putchar is now also a wrapper of fputc. Other than possibly minor speedup, this can also help buffered streams remain buffered, because the codepage conversion using writeCon_utf8 is unbuffered and first flushes the stream, so by avoiding the conversion and calling the libc API directly, we also avoid premature flush of a buffered stream. This did happen, as "time" is buffered since commit 54dbf0fa5, so previously it was flushed early when using putchar, while now it remains buffered by default (but can still be flushed early if the -f format string contains non-ASCII chars).
-rw-r--r--win32/winansi.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/win32/winansi.c b/win32/winansi.c
index dc98b9d2b..0dd2e17f2 100644
--- a/win32/winansi.c
+++ b/win32/winansi.c
@@ -850,13 +850,7 @@ static int ansi_emulate(const char *s, FILE *stream)
850 850
851int winansi_putchar(int c) 851int winansi_putchar(int c)
852{ 852{
853 char t = c; 853 return winansi_fputc(c, stdout);
854 char *s = &t;
855
856 if (!is_console(STDOUT_FILENO))
857 return putchar(c);
858
859 return conv_fwriteCon(stdout, s, 1) == EOF ? EOF : (unsigned char)c;
860} 854}
861 855
862int winansi_puts(const char *s) 856int winansi_puts(const char *s)
@@ -947,7 +941,7 @@ int winansi_fputc(int c, FILE *stream)
947 char t = c; 941 char t = c;
948 char *s = &t; 942 char *s = &t;
949 943
950 if (!is_console(fileno(stream))) { 944 if ((unsigned char)c <= 0x7f || !is_console(fileno(stream))) {
951 SetLastError(0); 945 SetLastError(0);
952 if ((ret=fputc(c, stream)) == EOF) 946 if ((ret=fputc(c, stream)) == EOF)
953 check_pipe(stream); 947 check_pipe(stream);