diff options
author | Ron Yorston <rmy@pobox.com> | 2023-08-25 13:44:13 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-25 13:44:13 +0000 |
commit | 8abbf4599d4ea84f084a7ce2832b59a793607699 (patch) | |
tree | 901a0bd4f6992ddc1f480ea450c810efef0e221e | |
parent | fb4be267c5878a0128775ba2a436c3e80519e2b6 (diff) | |
parent | 5862b6920d519974c2453529bdfd6832dd06f807 (diff) | |
download | busybox-w32-8abbf4599d4ea84f084a7ce2832b59a793607699.tar.gz busybox-w32-8abbf4599d4ea84f084a7ce2832b59a793607699.tar.bz2 busybox-w32-8abbf4599d4ea84f084a7ce2832b59a793607699.zip |
Merge pull request #355 from avih/utf8-output-speedup
win32: UTF8_OUTPUT: speedup for big outputs
-rw-r--r-- | win32/winansi.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/win32/winansi.c b/win32/winansi.c index c88c096d2..591154378 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
@@ -1457,10 +1457,16 @@ static int writeCon_utf8(int fd, const char *u8buf, size_t u8siz) | |||
1457 | static int state = 0; // -1: bad, 0-3: remaining cp bytes (0: done/new) | 1457 | static int state = 0; // -1: bad, 0-3: remaining cp bytes (0: done/new) |
1458 | static uint32_t codepoint = 0; // accumulated from up to 4 UTF8 bytes | 1458 | static uint32_t codepoint = 0; // accumulated from up to 4 UTF8 bytes |
1459 | 1459 | ||
1460 | // not a state, only avoids re-alloc on every call | ||
1461 | static const int wbufwsiz = 4096; | ||
1462 | static wchar_t *wbuf = 0; | ||
1463 | |||
1460 | HANDLE h = (HANDLE)_get_osfhandle(fd); | 1464 | HANDLE h = (HANDLE)_get_osfhandle(fd); |
1461 | wchar_t wbuf[256]; | ||
1462 | int wlen = 0; | 1465 | int wlen = 0; |
1463 | 1466 | ||
1467 | if (!wbuf) | ||
1468 | wbuf = xmalloc(wbufwsiz * sizeof(wchar_t)); | ||
1469 | |||
1464 | // ASCII7 uses least logic, then UTF8 continuations, UTF8 lead, errors | 1470 | // ASCII7 uses least logic, then UTF8 continuations, UTF8 lead, errors |
1465 | while (u8siz--) { | 1471 | while (u8siz--) { |
1466 | unsigned char c = *u8buf++; | 1472 | unsigned char c = *u8buf++; |
@@ -1512,7 +1518,7 @@ static int writeCon_utf8(int fd, const char *u8buf, size_t u8siz) | |||
1512 | } | 1518 | } |
1513 | 1519 | ||
1514 | // flush if we have less than two empty spaces | 1520 | // flush if we have less than two empty spaces |
1515 | if (wlen > ARRAY_SIZE(wbuf) - 2) { | 1521 | if (wlen > wbufwsiz - 2) { |
1516 | if (!WriteConsoleW(h, wbuf, wlen, 0, 0)) | 1522 | if (!WriteConsoleW(h, wbuf, wlen, 0, 0)) |
1517 | return -1; | 1523 | return -1; |
1518 | wlen = 0; | 1524 | wlen = 0; |