git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] index-pack: rationalize unpack_entry_data()

From
Nicolas Pitre <nico@fluxnic.net>
Date
Apr 12, 2010, 02:57 UTC
Message-ID
<1271041047-32563-2-git-send-email-nico@fluxnic.net>
In-Reply-To
<1271041047-32563-1-git-send-email-nico@fluxnic.net>

Rework the loop to remove duplicated calls to use() and fill(), and to make the code easier to read.

Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
---
 builtin/index-pack.c |   19 ++++++++-----------
 1 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index c746d3b..69b9167 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -266,27 +266,24 @@ static void unlink_base_data(struct base_data *c)
 
 static void *unpack_entry_data(unsigned long offset, unsigned long size)
 {
+	int status;
 	z_stream stream;
 	void *buf = xmalloc(size);
 
 	memset(&stream, 0, sizeof(stream));
+	git_inflate_init(&stream);
 	stream.next_out = buf;
 	stream.avail_out = size;
-	stream.next_in = fill(1);
-	stream.avail_in = input_len;
-	git_inflate_init(&stream);
 
-	for (;;) {
-		int ret = git_inflate(&stream, 0);
-		use(input_len - stream.avail_in);
-		if (stream.total_out == size && ret == Z_STREAM_END)
-			break;
-		if (ret != Z_OK)
-			bad_object(offset, "inflate returned %d", ret);
+	do {
 		stream.next_in = fill(1);
 		stream.avail_in = input_len;
-	}
+		status = git_inflate(&stream, 0);
+		use(input_len - stream.avail_in);
+	} while (status == Z_OK);
 	git_inflate_end(&stream);
+	if (stream.total_out != size || status != Z_STREAM_END)
+		bad_object(offset, "inflate returned %d", status);
 	return buf;
 }
 
-- 
1.7.1.rc1.237.ge1730.dirty
Previous: Nicolas PitreNext: Johannes Sixt
Message 2 of 6 in “index-pack: smarter memory usage when resolving deltas”
  1. 1/2 index-pack: smarter memory usage when resolving deltasNicolas Pitre, Apr 12, 2010
  2. 2/2 index-pack: rationalize unpack_entry_data()Nicolas Pitre, Apr 12, 2010
  3. Johannes SixtApr 12, 2010
  4. Nicolas PitreApr 12, 2010
  5. Johannes SixtApr 12, 2010
  6. Nicolas PitreApr 12, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.