From eff51218fbcaa3cf6abfc3a53f2834bb1a005320 Mon Sep 17 00:00:00 2001 From: Jeffrey Morlan Date: Mon, 2 Mar 2009 20:00:26 +0000 Subject: [PATCH] Speed up batch file execution by reading a line at a time instead of a byte at a time. svn path=/trunk/; revision=39848 --- reactos/base/shell/cmd/misc.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/reactos/base/shell/cmd/misc.c b/reactos/base/shell/cmd/misc.c index 7053c5352fd..f25c3c7ad62 100644 --- a/reactos/base/shell/cmd/misc.c +++ b/reactos/base/shell/cmd/misc.c @@ -503,7 +503,6 @@ BOOL IsExistingDirectory (LPCTSTR pszPath) BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength) { LPSTR lpString; - CHAR ch; DWORD dwRead; INT len = 0; #ifdef _UNICODE @@ -511,18 +510,20 @@ BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength) #else lpString = lpBuffer; #endif - while ((--nBufferLength > 0) && - ReadFile(hFile, &ch, 1, &dwRead, NULL) && dwRead) + + if (ReadFile(hFile, lpString, nBufferLength - 1, &dwRead, NULL)) { - lpString[len++] = ch; - if (ch == '\n') + /* break at new line*/ + CHAR *end = memchr(lpString, '\n', dwRead); + len = dwRead; + if (end) { - /* break at new line*/ - break; + len = (end - lpString) + 1; + SetFilePointer(hFile, len - dwRead, NULL, FILE_CURRENT); } } - if (!dwRead && !len) + if (!len) { #ifdef _UNICODE cmd_free(lpString);