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

Re: [PATCH] assorted delta code cleanup

From
Matthias Urlichs <smurf@smurf.noris.de>
Date
Jun 29, 2005, 07:10 UTC
Message-ID
<pan.2005.06.29.07.10.16.473252@smurf.noris.de>
In-Reply-To
<Pine.LNX.4.63.0506290246130.1667@localhost.localdomain>
Hi, Nicolas Pitre wrote:
> This is a wrap-up patch including all the cleanups I've done to the
> delta code and its usage. 

FWIW, I think Linus said he'd prefer a do/while loop. In fact this old code ...

Show 16 quoted lines
> -static unsigned long parse_delta_size(unsigned char **p)
> -{
> -	unsigned char c;
> -	unsigned long size = 0;
> -	unsigned shift = 0;
> -	unsigned char *data = *p;
> -
> -	do {
> -		c = *data++;
> -		size += (c & 0x7f) << shift;
> -		shift += 7;
> -	} while (c & 0x80);
> -	*p = data;
> -	return size;
> -}
> -
... is IMHO much more readable than this ...
Show 15 quoted lines
> +static inline unsigned long get_delta_hdr_size(const unsigned char **datap)
> +{
> +	const unsigned char *data = *datap;
> +	unsigned char cmd = *data++;
> +	unsigned long size = cmd & ~0x80;
> +	int i = 7;
> +	while (cmd & 0x80) {
> +		cmd = *data++;
> +		size |= (cmd & ~0x80) << i;
> +		i += 7;
> +	}
> +	*datap = data;
> +	return size;
> +}
> +
(except that the first += should be |= ).

Yeah, I know, it's nitpicking. Regard it as a testimony to the code's quality that I didn't see worse. ;-)

NB, it might be a good idea to exit with an error if the shift exceeds 31.
-- 
Matthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de
Disclaimer: The quote was selected randomly. Really. | http://smurf.noris.de
 - -
When it's fall in New York, the air smells as if someone's been frying
goats in it, and if you are keen to breathe the best plan is to open a
window and stick your head in a building.
		-- The Hitch Hiker's Guide to the Galaxy
Previous: Nicolas PitreNext: Junio C Hamano
Message 2 of 3 in “assorted delta code cleanup”
  1. assorted delta code cleanupNicolas Pitre, Jun 29, 2005
  2. Matthias UrlichsJun 29, 2005
  3. Fixlets on top of Nico's clean-up.Junio C Hamano, Jun 29, 2005

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.