diff options
| author | Ron Yorston <rmy@pobox.com> | 2022-12-30 20:51:59 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2022-12-30 20:56:56 +0000 |
| commit | 2b4dbe5fa8dc02d9cf4849fbda3197a522f16002 (patch) | |
| tree | 05688319cb5e8abb393b881c4be4a062d0be4a01 | |
| parent | de95d1d8f83d30b0ab08697b5c9a1899a0b26352 (diff) | |
| download | busybox-w32-2b4dbe5fa8dc02d9cf4849fbda3197a522f16002.tar.gz busybox-w32-2b4dbe5fa8dc02d9cf4849fbda3197a522f16002.tar.bz2 busybox-w32-2b4dbe5fa8dc02d9cf4849fbda3197a522f16002.zip | |
libbb: speed up bb_get_chunk_from_file()
Use _getc_nolock() in bb_get_chunk_from_file() and perform code
page translation on the resulting string. This speeds up grep by
another factor of two.
(GitHub issue #278)
| -rw-r--r-- | libbb/get_line_from_file.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/libbb/get_line_from_file.c b/libbb/get_line_from_file.c index 929bab78a..ce5c7810e 100644 --- a/libbb/get_line_from_file.c +++ b/libbb/get_line_from_file.c | |||
| @@ -16,7 +16,11 @@ char* FAST_FUNC bb_get_chunk_from_file(FILE *file, size_t *end) | |||
| 16 | size_t idx = 0; | 16 | size_t idx = 0; |
| 17 | char *linebuf = NULL; | 17 | char *linebuf = NULL; |
| 18 | 18 | ||
| 19 | #if ENABLE_PLATFORM_MINGW32 | ||
| 20 | while ((ch = _getc_nolock(file)) != EOF) { | ||
| 21 | #else | ||
| 19 | while ((ch = getc(file)) != EOF) { | 22 | while ((ch = getc(file)) != EOF) { |
| 23 | #endif | ||
| 20 | /* grow the line buffer as necessary */ | 24 | /* grow the line buffer as necessary */ |
| 21 | if (!(idx & 0xff)) { | 25 | if (!(idx & 0xff)) { |
| 22 | if (idx == ((size_t)-1) - 0xff) | 26 | if (idx == ((size_t)-1) - 0xff) |
| @@ -41,6 +45,11 @@ char* FAST_FUNC bb_get_chunk_from_file(FILE *file, size_t *end) | |||
| 41 | linebuf = xrealloc(linebuf, idx + 1); | 45 | linebuf = xrealloc(linebuf, idx + 1); |
| 42 | linebuf[idx] = '\0'; | 46 | linebuf[idx] = '\0'; |
| 43 | } | 47 | } |
| 48 | #if ENABLE_PLATFORM_MINGW32 | ||
| 49 | if (idx && isatty(fileno(file)) && | ||
| 50 | GetStdHandle(STD_INPUT_HANDLE) != INVALID_HANDLE_VALUE) | ||
| 51 | OemToCharBuff(linebuf, linebuf, idx); | ||
| 52 | #endif | ||
| 44 | return linebuf; | 53 | return linebuf; |
| 45 | } | 54 | } |
| 46 | 55 | ||
