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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 05, 2013 at 02:19:54AM -0400, Nicolas Pitre wrote:
> ... replacing the equivalent open coded loop.
> 
> Signed-off-by: Nicolas Pitre <nico@xxxxxxxxxxx>
> ---
>  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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]