From de95d1d8f83d30b0ab08697b5c9a1899a0b26352 Mon Sep 17 00:00:00 2001
From: Ron Yorston <rmy@pobox.com>
Date: Fri, 30 Dec 2022 15:13:55 +0000
Subject: 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)
---
 win32/winansi.c | 4 ++--
 1 file 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)
 	return isatty(fd) && get_console() != INVALID_HANDLE_VALUE;
 }
 
-static int is_console_in(int fd)
+static ALWAYS_INLINE int is_console_in(int fd)
 {
 	return isatty(fd) && GetStdHandle(STD_INPUT_HANDLE) != INVALID_HANDLE_VALUE;
 }
@@ -1083,7 +1083,7 @@ int winansi_getc(FILE *stream)
 {
 	int rv;
 
-	rv = getc(stream);
+	rv = _getc_nolock(stream);
 	if (!is_console_in(fileno(stream)))
 		return rv;
 
-- 
cgit v1.2.3-55-g6feb