aboutsummaryrefslogtreecommitdiff
path: root/win32/winansi.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2022-12-30 15:13:55 +0000
committerRon Yorston <rmy@pobox.com>2022-12-30 15:13:55 +0000
commitde95d1d8f83d30b0ab08697b5c9a1899a0b26352 (patch)
treec82099ae5c790fce72213ca4ab2cad5b7d957b47 /win32/winansi.c
parent67aec6403c80b8956b8b0f78f58e2b9664bd4f62 (diff)
downloadbusybox-w32-de95d1d8f83d30b0ab08697b5c9a1899a0b26352.tar.gz
busybox-w32-de95d1d8f83d30b0ab08697b5c9a1899a0b26352.tar.bz2
busybox-w32-de95d1d8f83d30b0ab08697b5c9a1899a0b26352.zip
win32: speed up getc(3) wrapper
The grep applet was found to be rather slow. A major reason for this is the implementation of getc(3). Using _getc_nolock() and inlining is_console_in() speeds things up by a factor of three. (GitHub issue #278)
Diffstat (limited to '')
-rw-r--r--win32/winansi.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/win32/winansi.c b/win32/winansi.c
index a78d5f7e9..9db11cddb 100644
--- a/win32/winansi.c
+++ b/win32/winansi.c
@@ -51,7 +51,7 @@ static int is_console(int fd)
51 return isatty(fd) && get_console() != INVALID_HANDLE_VALUE; 51 return isatty(fd) && get_console() != INVALID_HANDLE_VALUE;
52} 52}
53 53
54static int is_console_in(int fd) 54static ALWAYS_INLINE int is_console_in(int fd)
55{ 55{
56 return isatty(fd) && GetStdHandle(STD_INPUT_HANDLE) != INVALID_HANDLE_VALUE; 56 return isatty(fd) && GetStdHandle(STD_INPUT_HANDLE) != INVALID_HANDLE_VALUE;
57} 57}
@@ -1083,7 +1083,7 @@ int winansi_getc(FILE *stream)
1083{ 1083{
1084 int rv; 1084 int rv;
1085 1085
1086 rv = getc(stream); 1086 rv = _getc_nolock(stream);
1087 if (!is_console_in(fileno(stream))) 1087 if (!is_console_in(fileno(stream)))
1088 return rv; 1088 return rv;
1089 1089