From 60c668f1dccc77800548ec54587724ee9e61f4e3 Mon Sep 17 00:00:00 2001 From: Timo Teras Date: Thu, 30 Jul 2009 09:11:14 +0300 Subject: [PATCH] io: keep static pointer to copying buffer so we avoid some malloc/free calls. --- src/io.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/io.c b/src/io.c index 0fa1f88..8739752 100644 --- a/src/io.c +++ b/src/io.c @@ -112,6 +112,7 @@ size_t apk_istream_skip(struct apk_istream *is, size_t size) size_t apk_istream_splice(void *stream, int fd, size_t size, apk_progress_cb cb, void *cb_ctx) { + static void *splice_buffer = NULL; struct apk_istream *is = (struct apk_istream *) stream; unsigned char *buf = MAP_FAILED; size_t bufsz, done = 0, r, togo, mmapped = 0; @@ -128,12 +129,13 @@ size_t apk_istream_splice(void *stream, int fd, size_t size, } } if (!mmapped) { - if (bufsz > 256*1024) - bufsz = 256*1024; - - buf = malloc(bufsz); + if (splice_buffer == NULL) + splice_buffer = malloc(256*1024); + buf = splice_buffer; if (buf == NULL) return -ENOMEM; + if (bufsz > 256*1024) + bufsz = 256*1024; } while (done < size) { @@ -163,8 +165,6 @@ size_t apk_istream_splice(void *stream, int fd, size_t size, err: if (mmapped) munmap(buf, size); - else - free(buf); return r; }