small cleanup for diff-delta.c
This patch removes unused remnants of the original xdiff source. No functional change. Possible tiny speed improvement. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
1403959cc8
commit
e5e3a9d8f9
34
diff-delta.c
34
diff-delta.c
@ -84,20 +84,15 @@ typedef struct s_chanode {
|
|||||||
} chanode_t;
|
} chanode_t;
|
||||||
|
|
||||||
typedef struct s_chastore {
|
typedef struct s_chastore {
|
||||||
chanode_t *head, *tail;
|
|
||||||
int isize, nsize;
|
int isize, nsize;
|
||||||
chanode_t *ancur;
|
chanode_t *ancur;
|
||||||
chanode_t *sncur;
|
|
||||||
int scurr;
|
|
||||||
} chastore_t;
|
} chastore_t;
|
||||||
|
|
||||||
static void cha_init(chastore_t *cha, int isize, int icount)
|
static void cha_init(chastore_t *cha, int isize, int icount)
|
||||||
{
|
{
|
||||||
cha->head = cha->tail = NULL;
|
|
||||||
cha->isize = isize;
|
cha->isize = isize;
|
||||||
cha->nsize = icount * isize;
|
cha->nsize = icount * isize;
|
||||||
cha->ancur = cha->sncur = NULL;
|
cha->ancur = NULL;
|
||||||
cha->scurr = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *cha_alloc(chastore_t *cha)
|
static void *cha_alloc(chastore_t *cha)
|
||||||
@ -111,12 +106,7 @@ static void *cha_alloc(chastore_t *cha)
|
|||||||
if (!ancur)
|
if (!ancur)
|
||||||
return NULL;
|
return NULL;
|
||||||
ancur->icurr = 0;
|
ancur->icurr = 0;
|
||||||
ancur->next = NULL;
|
ancur->next = cha->ancur;
|
||||||
if (cha->tail)
|
|
||||||
cha->tail->next = ancur;
|
|
||||||
if (!cha->head)
|
|
||||||
cha->head = ancur;
|
|
||||||
cha->tail = ancur;
|
|
||||||
cha->ancur = ancur;
|
cha->ancur = ancur;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +117,7 @@ static void *cha_alloc(chastore_t *cha)
|
|||||||
|
|
||||||
static void cha_free(chastore_t *cha)
|
static void cha_free(chastore_t *cha)
|
||||||
{
|
{
|
||||||
chanode_t *cur = cha->head;
|
chanode_t *cur = cha->ancur;
|
||||||
while (cur) {
|
while (cur) {
|
||||||
chanode_t *tmp = cur;
|
chanode_t *tmp = cur;
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
@ -142,7 +132,6 @@ typedef struct s_bdrecord {
|
|||||||
} bdrecord_t;
|
} bdrecord_t;
|
||||||
|
|
||||||
typedef struct s_bdfile {
|
typedef struct s_bdfile {
|
||||||
const unsigned char *data, *top;
|
|
||||||
chastore_t cha;
|
chastore_t cha;
|
||||||
unsigned int fphbits;
|
unsigned int fphbits;
|
||||||
bdrecord_t **fphash;
|
bdrecord_t **fphash;
|
||||||
@ -152,7 +141,7 @@ static int delta_prepare(const unsigned char *buf, int bufsize, bdfile_t *bdf)
|
|||||||
{
|
{
|
||||||
unsigned int fphbits;
|
unsigned int fphbits;
|
||||||
int i, hsize;
|
int i, hsize;
|
||||||
const unsigned char *base, *data, *top;
|
const unsigned char *data, *top;
|
||||||
bdrecord_t *brec;
|
bdrecord_t *brec;
|
||||||
bdrecord_t **fphash;
|
bdrecord_t **fphash;
|
||||||
|
|
||||||
@ -165,13 +154,12 @@ static int delta_prepare(const unsigned char *buf, int bufsize, bdfile_t *bdf)
|
|||||||
fphash[i] = NULL;
|
fphash[i] = NULL;
|
||||||
cha_init(&bdf->cha, sizeof(bdrecord_t), hsize / 4 + 1);
|
cha_init(&bdf->cha, sizeof(bdrecord_t), hsize / 4 + 1);
|
||||||
|
|
||||||
bdf->data = data = base = buf;
|
top = buf + bufsize;
|
||||||
bdf->top = top = buf + bufsize;
|
data = buf + (bufsize / BLK_SIZE) * BLK_SIZE;
|
||||||
data += (bufsize / BLK_SIZE) * BLK_SIZE;
|
|
||||||
if (data == top)
|
if (data == top)
|
||||||
data -= BLK_SIZE;
|
data -= BLK_SIZE;
|
||||||
|
|
||||||
for ( ; data >= base; data -= BLK_SIZE) {
|
for ( ; data >= buf; data -= BLK_SIZE) {
|
||||||
brec = cha_alloc(&bdf->cha);
|
brec = cha_alloc(&bdf->cha);
|
||||||
if (!brec) {
|
if (!brec) {
|
||||||
cha_free(&bdf->cha);
|
cha_free(&bdf->cha);
|
||||||
@ -208,7 +196,7 @@ void *diff_delta(void *from_buf, unsigned long from_size,
|
|||||||
{
|
{
|
||||||
int i, outpos, outsize, inscnt, csize, msize, moff;
|
int i, outpos, outsize, inscnt, csize, msize, moff;
|
||||||
unsigned int fp;
|
unsigned int fp;
|
||||||
const unsigned char *data, *top, *ptr1, *ptr2;
|
const unsigned char *ref_data, *ref_top, *data, *top, *ptr1, *ptr2;
|
||||||
unsigned char *out, *orig;
|
unsigned char *out, *orig;
|
||||||
bdrecord_t *brec;
|
bdrecord_t *brec;
|
||||||
bdfile_t bdf;
|
bdfile_t bdf;
|
||||||
@ -224,6 +212,8 @@ void *diff_delta(void *from_buf, unsigned long from_size,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ref_data = from_buf;
|
||||||
|
ref_top = from_buf + from_size;
|
||||||
data = to_buf;
|
data = to_buf;
|
||||||
top = to_buf + to_size;
|
top = to_buf + to_size;
|
||||||
|
|
||||||
@ -253,7 +243,7 @@ void *diff_delta(void *from_buf, unsigned long from_size,
|
|||||||
i = HASH(fp, bdf.fphbits);
|
i = HASH(fp, bdf.fphbits);
|
||||||
for (brec = bdf.fphash[i]; brec; brec = brec->next) {
|
for (brec = bdf.fphash[i]; brec; brec = brec->next) {
|
||||||
if (brec->fp == fp) {
|
if (brec->fp == fp) {
|
||||||
csize = bdf.top - brec->ptr;
|
csize = ref_top - brec->ptr;
|
||||||
if (csize > top - data)
|
if (csize > top - data)
|
||||||
csize = top - data;
|
csize = top - data;
|
||||||
for (ptr1 = brec->ptr, ptr2 = data;
|
for (ptr1 = brec->ptr, ptr2 = data;
|
||||||
@ -262,7 +252,7 @@ void *diff_delta(void *from_buf, unsigned long from_size,
|
|||||||
|
|
||||||
csize = ptr1 - brec->ptr;
|
csize = ptr1 - brec->ptr;
|
||||||
if (csize > msize) {
|
if (csize > msize) {
|
||||||
moff = brec->ptr - bdf.data;
|
moff = brec->ptr - ref_data;
|
||||||
msize = csize;
|
msize = csize;
|
||||||
if (msize >= 0x10000) {
|
if (msize >= 0x10000) {
|
||||||
msize = 0x10000;
|
msize = 0x10000;
|
||||||
|
Loading…
Reference in New Issue
Block a user