Author: jmorlan Date: Mon Mar 2 23:00:26 2009 New Revision: 39848
URL: http://svn.reactos.org/svn/reactos?rev=39848&view=rev Log: Speed up batch file execution by reading a line at a time instead of a byte at a time.
Modified: trunk/reactos/base/shell/cmd/misc.c
Modified: trunk/reactos/base/shell/cmd/misc.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/misc.c?rev=3... ============================================================================== --- trunk/reactos/base/shell/cmd/misc.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/misc.c [iso-8859-1] Mon Mar 2 23:00:26 2009 @@ -503,7 +503,6 @@ BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength) { LPSTR lpString; - CHAR ch; DWORD dwRead; INT len = 0; #ifdef _UNICODE @@ -511,18 +510,20 @@ #else lpString = lpBuffer; #endif - while ((--nBufferLength > 0) && - ReadFile(hFile, &ch, 1, &dwRead, NULL) && dwRead) - { - lpString[len++] = ch; - if (ch == '\n') - { - /* break at new line*/ - break; - } - } - - if (!dwRead && !len) + + if (ReadFile(hFile, lpString, nBufferLength - 1, &dwRead, NULL)) + { + /* break at new line*/ + CHAR *end = memchr(lpString, '\n', dwRead); + len = dwRead; + if (end) + { + len = (end - lpString) + 1; + SetFilePointer(hFile, len - dwRead, NULL, FILE_CURRENT); + } + } + + if (!len) { #ifdef _UNICODE cmd_free(lpString);