From: Matthias Urlichs <smurf@smurf.noris.de>
To: git@vger.kernel.org
Subject: Re: [PATCH] assorted delta code cleanup
Date: Wed, 29 Jun 2005 09:10:20 +0200 [thread overview]
Message-ID: <pan.2005.06.29.07.10.16.473252@smurf.noris.de> (raw)
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 ...
> -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 ...
> +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
next prev parent reply other threads:[~2005-06-29 7:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-29 6:49 [PATCH] assorted delta code cleanup Nicolas Pitre
2005-06-29 7:10 ` Matthias Urlichs [this message]
2005-06-29 7:32 ` [PATCH] Fixlets on top of Nico's clean-up Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pan.2005.06.29.07.10.16.473252@smurf.noris.de \
--to=smurf@smurf.noris.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox