threads / patch / 5392

patch, 5 partsCleanup unpack_object_header to use only offsets.

Subject: [PATCH 4/5] Cleanup unpack_object_header to use only offsets.

## tl;dr

One message between Aug 26, 2006 and Aug 26, 2006. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Shawn Pearce· Aug 26, 2006, 08:12 UTC · lore

If we're always incrementing both the offset and the pointer we aren't gaining anything by keeping both. Instead just use the offset since that's what we were given and what we are expected to return. Also using offset is likely to make it easier to remap the pack in the future should partial mapping of very large packs get implemented.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 sha1_file.c |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)
Show changes to sha1_file.c +3 −7
diff --git a/sha1_file.c b/sha1_file.c
index b580cee..e6d47c1 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -917,23 +917,19 @@ static unsigned long unpack_object_heade
 	enum object_type *type, unsigned long *sizep)
 {
 	unsigned shift;
-	unsigned char *pack, c;
+	unsigned char c;
 	unsigned long size;
 
 	if (offset >= p->pack_size)
 		die("object offset outside of pack file");
-
-	pack =  (unsigned char *) p->pack_base + offset;
-	c = *pack++;
-	offset++;
+	c = *((unsigned char *)p->pack_base + offset++);
 	*type = (c >> 4) & 7;
 	size = c & 15;
 	shift = 4;
 	while (c & 0x80) {
 		if (offset >= p->pack_size)
 			die("object offset outside of pack file");
-		c = *pack++;
-		offset++;
+		c = *((unsigned char *)p->pack_base + offset++);
 		size += (c & 0x7f) << shift;
 		shift += 7;
 	}
-- 
1.4.2.g6580

← back to recent threads