From d3cef27b10ec91b14c917f52ff0d4550d81327f6 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 19 Oct 2023 12:51:38 -0500 Subject: [PATCH] Switch yes to writev() a redundant iovec to produce output in bigger chunks, speeding it up from megabytes to gigabytes. Also, move #include uio.h from dd.c to toys.h (it's posix, and has a second user now), and fnmatch.h moved into portability.h for horrible glibc sequencing reasons so remove second NOP #include of the same header. --- toys.h | 2 +- toys/other/yes.c | 34 +++++++++++++++++++++++++--------- toys/posix/dd.c | 1 - 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/toys.h b/toys.h index 49b02ffb..bde3d90d 100644 --- a/toys.h +++ b/toys.h @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -37,6 +36,7 @@ #include #include #include +#include #include #include #include diff --git a/toys/other/yes.c b/toys/other/yes.c index 8edba0ae..6e7887ee 100644 --- a/toys/other/yes.c +++ b/toys/other/yes.c @@ -2,7 +2,7 @@ * * Copyright 2007 Rob Landley -USE_YES(NEWTOY(yes, NULL, TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LINEBUF)) +USE_YES(NEWTOY(yes, 0, TOYFLAG_USR|TOYFLAG_BIN)) config YES bool "yes" @@ -17,13 +17,29 @@ config YES void yes_main(void) { - for (;;) { - int i; - for (i=0; toys.optargs[i]; i++) { - if (i) xputc(' '); - xprintf("%s", toys.optargs[i]); - } - if (!i) xputc('y'); - xputc('\n'); + struct iovec *iov = (void *)toybuf; + char *out, *ss; + long len, ll, i, j; + + // Collate command line arguments into one string, or repeated "y\n". + for (len = i = 0; toys.optargs[i]; i++) len += strlen(toys.optargs[i]) + 1; + ss = out = xmalloc(len ? : 128); + if (!i) for (i = 0; i<64; i++) { + *ss++ = 'y'; + *ss++ = '\n'; + } else { + for (i = 0; toys.optargs[i]; i++) + ss += sprintf(ss, " %s"+!i, toys.optargs[i]); + *ss++ = '\n'; + } + + // Populate a redundant iovec[] outputting the same string many times + for (i = ll = 0; i(j = writev(1, iov, i))) perror_exit(0); } diff --git a/toys/posix/dd.c b/toys/posix/dd.c index 4c9670e7..7fc721fc 100644 --- a/toys/posix/dd.c +++ b/toys/posix/dd.c @@ -40,7 +40,6 @@ config DD #define FOR_dd #include "toys.h" -#include GLOBALS( // Display fields -- 2.39.2