Thread (113 messages) flat view 113 messages, 3 authors, 2016-06-15

Re: [PATCH 31/38] sha1_file.c: make use of decode_varint()

From: SZEDER Gábor <hidden>
Date: 2016-06-15 22:58:38

On Thu, Sep 05, 2013 at 02:19:54AM -0400, Nicolas Pitre wrote:
quoted hunk ↗ jump to hunk
... replacing the equivalent open coded loop.

Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
---
 sha1_file.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index a298933..67eb903 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1687,20 +1687,12 @@ static off_t get_delta_base(struct packed_git *p,
 	 * is stupid, as then a REF_DELTA would be smaller to store.
 	 */
 	if (type == OBJ_OFS_DELTA) {
-		unsigned used = 0;
-		unsigned char c = base_info[used++];
-		base_offset = c & 127;
-		while (c & 128) {
-			base_offset += 1;
-			if (!base_offset || MSB(base_offset, 7))
-				return 0;  /* overflow */
-			c = base_info[used++];
-			base_offset = (base_offset << 7) + (c & 127);
-		}
+		const unsigned char *cp = base_info;
+		base_offset = decode_varint(&cp);
 		base_offset = delta_obj_offset - base_offset;
 		if (base_offset <= 0 || base_offset >= delta_obj_offset)
 			return 0;  /* out of bound */
-		*curpos += used;
+		*curpos += cp - base_info;
 	} else if (type == OBJ_REF_DELTA) {
 		/* The base entry _must_ be in the same pack */
 		base_offset = find_pack_entry_one(base_info, p);
-- 
1.8.4.38.g317e65b
This patch seems to be a cleanup independent from pack v4, it applies
cleanly on master and passes all tests in itself.

Best,
Gábor
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help