aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2026-05-10 13:00:34 +0100
committerRon Yorston <rmy@pobox.com>2026-05-10 13:00:34 +0100
commitcc5bbc507aeefc3c5cf67e78930ebf715324d06e (patch)
tree8aa5bd735788b0b8b9a7e337768c54c0ba589e37
parentc4f24ec9d3a88346e416b11ac47144778aa01696 (diff)
downloadbusybox-w32-cc5bbc507aeefc3c5cf67e78930ebf715324d06e.tar.gz
busybox-w32-cc5bbc507aeefc3c5cf67e78930ebf715324d06e.tar.bz2
busybox-w32-cc5bbc507aeefc3c5cf67e78930ebf715324d06e.zip
libbb: reverse performance regression in bb_copyfd_*
Commit c4f24ec9d (libbb: try to mitigate 'cat /dev/urandom') resulted in a 'cat' to the terminal taking ~25% longer than before. Raising the isatty() call out of the loop reduces the penalty to ~1%. Adds 16 bytes in the 32-bit build. (GitHub issue #585)
-rw-r--r--libbb/copyfd.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/libbb/copyfd.c b/libbb/copyfd.c
index 706f6bd66..e70e7d8ad 100644
--- a/libbb/copyfd.c
+++ b/libbb/copyfd.c
@@ -46,6 +46,9 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
46 char buffer[CONFIG_FEATURE_COPYBUF_KB * 1024]; 46 char buffer[CONFIG_FEATURE_COPYBUF_KB * 1024];
47 enum { buffer_size = sizeof(buffer) }; 47 enum { buffer_size = sizeof(buffer) };
48#endif 48#endif
49#if ENABLE_PLATFORM_MINGW32
50 int dst_is_tty = isatty(dst_fd);
51#endif
49 52
50 if (size < 0) { 53 if (size < 0) {
51 size = -size; 54 size = -size;
@@ -106,7 +109,7 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
106 if (dst_fd >= 0 && !sendfile_sz) { 109 if (dst_fd >= 0 && !sendfile_sz) {
107 ssize_t wr = full_write(dst_fd, buffer, rd); 110 ssize_t wr = full_write(dst_fd, buffer, rd);
108#if ENABLE_PLATFORM_MINGW32 111#if ENABLE_PLATFORM_MINGW32
109 if (isatty(dst_fd)) 112 if (dst_is_tty)
110 sleepms(); 113 sleepms();
111#endif 114#endif
112 if (wr < rd) { 115 if (wr < rd) {