git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] reduce delta head inflated size
@ 2006-10-18 19:56 Nicolas Pitre
  2006-10-19 13:49 ` Morten Welinder
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Pitre @ 2006-10-18 19:56 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Supposing that both the base and result sizes were both full size 64-bit 
values, their encoding would occupy only 9.2 bytes each.  Therefore 
inflating 64 bytes is way overkill.  Limit it to 20 bytes instead which 
should be plenty enough for a couple years to come.

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

---

diff --git a/sha1_file.c b/sha1_file.c
index 25c0bf9..e89d24c 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -943,7 +943,7 @@ static int packed_delta_info(struct pack
 
 	if (sizep) {
 		const unsigned char *data;
-		unsigned char delta_head[64];
+		unsigned char delta_head[20];
 		unsigned long result_size;
 		z_stream stream;
 		int st;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] reduce delta head inflated size
  2006-10-18 19:56 [PATCH] reduce delta head inflated size Nicolas Pitre
@ 2006-10-19 13:49 ` Morten Welinder
  2006-10-19 14:17   ` Nicolas Pitre
  0 siblings, 1 reply; 3+ messages in thread
From: Morten Welinder @ 2006-10-19 13:49 UTC (permalink / raw)
  To: Nicolas Pitre; +Cc: Junio C Hamano, git

On 10/18/06, Nicolas Pitre <nico@cam.org> wrote:
> Supposing that both the base and result sizes were both full size 64-bit
> values, their encoding would occupy only 9.2 bytes each.  Therefore
> inflating 64 bytes is way overkill.  Limit it to 20 bytes instead which
> should be plenty enough for a couple years to come.

2^63 ~ 9.2e18

Thus one signed 64-bit number can take up 1 sign + 19 digits + 1 nul.
That's 21 bytes.

If you don't like the constant, 4*sizeof(integer type) should work.
(Assuming sizeof measures in bytes.)

M.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] reduce delta head inflated size
  2006-10-19 13:49 ` Morten Welinder
@ 2006-10-19 14:17   ` Nicolas Pitre
  0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Pitre @ 2006-10-19 14:17 UTC (permalink / raw)
  To: Morten Welinder; +Cc: Junio C Hamano, git

On Thu, 19 Oct 2006, Morten Welinder wrote:

> On 10/18/06, Nicolas Pitre <nico@cam.org> wrote:
> > Supposing that both the base and result sizes were both full size 64-bit
> > values, their encoding would occupy only 9.2 bytes each.  Therefore
> > inflating 64 bytes is way overkill.  Limit it to 20 bytes instead which
> > should be plenty enough for a couple years to come.
> 
> 2^63 ~ 9.2e18
> 
> Thus one signed 64-bit number can take up 1 sign + 19 digits + 1 nul.
> That's 21 bytes.

No.  In this case the value is kept binary, with bits spread over 
consecutive bytes but with the MSB indicating continuation on the next 
byte.

This means 64 bits / 7 bits per byte = 9.1 bytes, hence 10.  Then there 
are 2 of those values that makes 20 bytes.


Nicolas

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-10-19 14:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-18 19:56 [PATCH] reduce delta head inflated size Nicolas Pitre
2006-10-19 13:49 ` Morten Welinder
2006-10-19 14:17   ` Nicolas Pitre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).