зеркало из https://github.com/microsoft/git.git
[PATCH] denser delta header encoding
Since the delta data format is not tied to any actual git object anymore, now is the time to add a small improvement to the delta data header as it is been done for packed object header. This patch allows for reducing the delta header of about 2 bytes and makes for simpler code. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
Родитель
9d5ab9625d
Коммит
69a2d426f0
|
@ -11,16 +11,13 @@
|
||||||
static unsigned long get_hdr_size(const unsigned char **datap)
|
static unsigned long get_hdr_size(const unsigned char **datap)
|
||||||
{
|
{
|
||||||
const unsigned char *data = *datap;
|
const unsigned char *data = *datap;
|
||||||
unsigned long size;
|
unsigned char cmd = *data++;
|
||||||
unsigned char cmd;
|
unsigned long size = cmd & ~0x80;
|
||||||
int i;
|
int i = 7;
|
||||||
size = i = 0;
|
while (cmd & 0x80) {
|
||||||
cmd = *data++;
|
cmd = *data++;
|
||||||
while (cmd) {
|
size |= (cmd & ~0x80) << i;
|
||||||
if (cmd & 1)
|
i += 7;
|
||||||
size |= *data++ << i;
|
|
||||||
i += 8;
|
|
||||||
cmd >>= 1;
|
|
||||||
}
|
}
|
||||||
*datap = data;
|
*datap = data;
|
||||||
return size;
|
return size;
|
||||||
|
@ -47,8 +44,8 @@ int count_delta(void *delta_buf, unsigned long delta_size,
|
||||||
unsigned char cmd;
|
unsigned char cmd;
|
||||||
unsigned long src_size, dst_size, out;
|
unsigned long src_size, dst_size, out;
|
||||||
|
|
||||||
/* the smallest delta size possible is 6 bytes */
|
/* the smallest delta size possible is 4 bytes */
|
||||||
if (delta_size < 6)
|
if (delta_size < 4)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
data = delta_buf;
|
data = delta_buf;
|
||||||
|
|
34
diff-delta.c
34
diff-delta.c
|
@ -228,28 +228,22 @@ void *diff_delta(void *from_buf, unsigned long from_size,
|
||||||
top = to_buf + to_size;
|
top = to_buf + to_size;
|
||||||
|
|
||||||
/* store reference buffer size */
|
/* store reference buffer size */
|
||||||
orig = out + outpos++;
|
out[outpos++] = from_size;
|
||||||
*orig = i = 0;
|
from_size >>= 7;
|
||||||
do {
|
while (from_size) {
|
||||||
if (from_size & 0xff) {
|
out[outpos - 1] |= 0x80;
|
||||||
*orig |= (1 << i);
|
out[outpos++] = from_size;
|
||||||
out[outpos++] = from_size;
|
from_size >>= 7;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
from_size >>= 8;
|
|
||||||
} while (from_size);
|
|
||||||
|
|
||||||
/* store target buffer size */
|
/* store target buffer size */
|
||||||
orig = out + outpos++;
|
out[outpos++] = to_size;
|
||||||
*orig = i = 0;
|
to_size >>= 7;
|
||||||
do {
|
while (to_size) {
|
||||||
if (to_size & 0xff) {
|
out[outpos - 1] |= 0x80;
|
||||||
*orig |= (1 << i);
|
out[outpos++] = to_size;
|
||||||
out[outpos++] = to_size;
|
to_size >>= 7;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
to_size >>= 8;
|
|
||||||
} while (to_size);
|
|
||||||
|
|
||||||
inscnt = 0;
|
inscnt = 0;
|
||||||
moff = 0;
|
moff = 0;
|
||||||
|
|
|
@ -22,33 +22,33 @@ void *patch_delta(void *src_buf, unsigned long src_size,
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* the smallest delta size possible is 6 bytes */
|
/* the smallest delta size possible is 4 bytes */
|
||||||
if (delta_size < 6)
|
if (delta_size < 4)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
data = delta_buf;
|
data = delta_buf;
|
||||||
top = delta_buf + delta_size;
|
top = delta_buf + delta_size;
|
||||||
|
|
||||||
/* make sure the orig file size matches what we expect */
|
/* make sure the orig file size matches what we expect */
|
||||||
size = i = 0;
|
|
||||||
cmd = *data++;
|
cmd = *data++;
|
||||||
while (cmd) {
|
size = cmd & ~0x80;
|
||||||
if (cmd & 1)
|
i = 7;
|
||||||
size |= *data++ << i;
|
while (cmd & 0x80) {
|
||||||
i += 8;
|
cmd = *data++;
|
||||||
cmd >>= 1;
|
size |= (cmd & ~0x80) << i;
|
||||||
|
i += 7;
|
||||||
}
|
}
|
||||||
if (size != src_size)
|
if (size != src_size)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* now the result size */
|
/* now the result size */
|
||||||
size = i = 0;
|
|
||||||
cmd = *data++;
|
cmd = *data++;
|
||||||
while (cmd) {
|
size = cmd & ~0x80;
|
||||||
if (cmd & 1)
|
i = 7;
|
||||||
size |= *data++ << i;
|
while (cmd & 0x80) {
|
||||||
i += 8;
|
cmd = *data++;
|
||||||
cmd >>= 1;
|
size |= (cmd & ~0x80) << i;
|
||||||
|
i += 7;
|
||||||
}
|
}
|
||||||
dst_buf = malloc(size);
|
dst_buf = malloc(size);
|
||||||
if (!dst_buf)
|
if (!dst_buf)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче