aboutsummaryrefslogtreecommitdiffstats
path: root/src/io.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-07-30 09:11:14 +0300
committerTimo Teras <timo.teras@iki.fi>2009-07-30 09:11:14 +0300
commit60c668f1dccc77800548ec54587724ee9e61f4e3 (patch)
treef958aa4f866083edca8ace47db7408b3bfff98e2 /src/io.c
parent8e4075e6b1911679ae3da837b5f13fb85c8f01f5 (diff)
downloadaports-60c668f1dccc77800548ec54587724ee9e61f4e3.tar.bz2
aports-60c668f1dccc77800548ec54587724ee9e61f4e3.tar.xz
io: keep static pointer to copying buffer
so we avoid some malloc/free calls.
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/io.c b/src/io.c
index 0fa1f88707..8739752d3d 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;
}