# [PATCH] delta micro optimization

3 messages from 2006-02-10 to 2006-02-10. Participants: Nicolas Pitre, Junio C Hamano.
Thread: https://gitlist.dev/t/3285

## Nicolas Pitre, 2006-02-10 18:42

Subject: [PATCH] delta micro optimization
Message-ID: <Pine.LNX.4.64.0602101335160.5397@localhost.localdomain>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0602101335160.5397%40localhost.localdomain

```
My kernel work habit made me look at the generated assembly for the 
delta code, and one obvious albeit small improvement is this patch.

Signed-off-by: Nicolas Pitre <nico@cam.org>

---

diff --git a/delta.h b/delta.h
index 31d1820..a15350d 100644
--- a/delta.h
+++ b/delta.h
@@ -19,14 +19,14 @@ extern void *patch_delta(void *src_buf, 
 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) {
+	unsigned char cmd;
+	unsigned long size = 0;
+	int i = 0;
+	do {
 		cmd = *data++;
 		size |= (cmd & ~0x80) << i;
 		i += 7;
-	}
+	} while (cmd & 0x80);
 	*datap = data;
 	return size;
 }

```

## Junio C Hamano, 2006-02-10 20:00

Subject: Re: [PATCH] delta micro optimization
Message-ID: <7vhd77vv9o.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vhd77vv9o.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <Pine.LNX.4.64.0602101335160.5397@localhost.localdomain>

```
That looks obviously correct but it really is micro.  Have you
benched it?  On which architectures?  Does it help everywhere or
register starved ones benefit more than others?

```

## Nicolas Pitre, 2006-02-10 20:38

Subject: Re: [PATCH] delta micro optimization
Message-ID: <Pine.LNX.4.64.0602101516310.5397@localhost.localdomain>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0602101516310.5397%40localhost.localdomain
In-Reply-To: <7vhd77vv9o.fsf@assigned-by-dhcp.cox.net>

```
On Fri, 10 Feb 2006, Junio C Hamano wrote:

> That looks obviously correct but it really is micro.  Have you
> benched it?  On which architectures?  Does it help everywhere or
> register starved ones benefit more than others?

I doubt the performance difference would be measurable on i386 although 
the code is a bit smaller.

On ARM it causes a code reduction of 12.5% in count-delta.o.


Nicolas

```
