From 4fd87e892eeb9bcb050e3f5bc3b5b5f92dc0f6aa Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Sun, 11 Aug 2019 18:56:13 +1000 Subject: aio: Significantly improve the speed of copyto Copying 1 byte at a time can be very slow for large transfers. Use a 256 byte buffer instead. Signed-off-by: Steve Bennett --- jim-aio.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/jim-aio.c b/jim-aio.c index 9d751c3..da3019f 100644 --- a/jim-aio.c +++ b/jim-aio.c @@ -752,15 +752,21 @@ static int aio_cmd_copy(Jim_Interp *interp, int argc, Jim_Obj *const *argv) } while (count < maxlen) { - char ch; + /* A reasonable compromise between stack size and speed */ + char buf[AIO_BUF_LEN]; + jim_wide len = maxlen - count; + if (len > sizeof(buf)) { + len = sizeof(buf); + } - if (af->fops->reader(af, &ch, 1) != 1) { + len = af->fops->reader(af, buf, len); + if (len <= 0) { break; } - if (outf->fops->writer(outf, &ch, 1) != 1) { + if (outf->fops->writer(outf, buf, len) != len) { break; } - count++; + count += len; } if (JimCheckStreamError(interp, af) || JimCheckStreamError(interp, outf)) { -- cgit v1.1