summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2019-08-11 18:56:13 +1000
committerSteve Bennett <steveb@workware.net.au>2019-08-14 17:11:17 +1000
commit4fd87e892eeb9bcb050e3f5bc3b5b5f92dc0f6aa (patch)
treea91999db627ca690a344c1c9a795f7c5640b258e
parent82e16356166d77acf5a78d198273ca64eb4a5bd4 (diff)
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 <steveb@workware.net.au>
-rw-r--r--jim-aio.c14
1 files 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)) {