summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7ce4721)
raw | patch | inline | side by side (parent: 7ce4721)
author | Nicolas Pitre <nico@fluxnic.net> | |
Mon, 12 Apr 2010 20:50:35 +0000 (16:50 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 12 Apr 2010 22:30:58 +0000 (15:30 -0700) |
In the same spirit as commit 9892bebafe, let's avoid allocating the full
buffer for the deflated data in write_compressed() in order to write it.
Let's deflate and write the data in chunks instead to reduce memory
usage.
Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
buffer for the deflated data in write_compressed() in order to write it.
Let's deflate and write the data in chunks instead to reduce memory
usage.
Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-index-pack.c | patch | blob | history |
diff --git a/builtin-index-pack.c b/builtin-index-pack.c
index 4308abb60e8cf750f3c3a38c2100f910b0bcbdf9..7f3208457567642cf5fa474a0dc3194ca0f808e8 100644 (file)
--- a/builtin-index-pack.c
+++ b/builtin-index-pack.c
static int write_compressed(struct sha1file *f, void *in, unsigned int size)
{
z_stream stream;
- unsigned long maxsize;
- void *out;
+ int status;
+ unsigned char outbuf[4096];
memset(&stream, 0, sizeof(stream));
deflateInit(&stream, zlib_compression_level);
- maxsize = deflateBound(&stream, size);
- out = xmalloc(maxsize);
-
- /* Compress it */
stream.next_in = in;
stream.avail_in = size;
- stream.next_out = out;
- stream.avail_out = maxsize;
- while (deflate(&stream, Z_FINISH) == Z_OK);
- deflateEnd(&stream);
+ do {
+ stream.next_out = outbuf;
+ stream.avail_out = sizeof(outbuf);
+ status = deflate(&stream, Z_FINISH);
+ sha1write(f, outbuf, sizeof(outbuf) - stream.avail_out);
+ } while (status == Z_OK);
+
+ if (status != Z_STREAM_END)
+ die("unable to deflate appended object (%d)", status);
size = stream.total_out;
- sha1write(f, out, size);
- free(out);
+ deflateEnd(&stream);
return size;
}