@matheusbsbs / matheus-bagliano / commits / e5e3a9d8f9
Fork 0

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>

Nicolas Pitre committed Dec 15, 2005 at 11:10 UTC e5e3a9d8f91685cbbb4099f1fdfb9798461ef5d4
1 file changed +12 -22
diff-delta.c
+12 -22
@@ -84,20 +84,15 @@ typedef struct s_chanode {
84 } chanode_t;
85
86 typedef struct s_chastore {
87 - chanode_t *head, *tail;
87 int isize, nsize;
88 chanode_t *ancur;
90 - chanode_t *sncur;
91 - int scurr;
89 } chastore_t;
90
91 static void cha_init(chastore_t *cha, int isize, int icount)
92 {
96 - cha->head = cha->tail = NULL;
93 cha->isize = isize;
94 cha->nsize = icount * isize;
99 - cha->ancur = cha->sncur = NULL;
100 - cha->scurr = 0;
95 + cha->ancur = NULL;
96 }
97
98 static void *cha_alloc(chastore_t *cha)
@@ -111,12 +106,7 @@ static void *cha_alloc(chastore_t *cha)
106 if (!ancur)
107 return NULL;
108 ancur->icurr = 0;
114 - ancur->next = NULL;
115 - if (cha->tail)
116 - cha->tail->next = ancur;
117 - if (!cha->head)
118 - cha->head = ancur;
119 - cha->tail = ancur;
109 + ancur->next = cha->ancur;
110 cha->ancur = ancur;
111 }
112
@@ -127,7 +117,7 @@ static void *cha_alloc(chastore_t *cha)
117
118 static void cha_free(chastore_t *cha)
119 {
130 - chanode_t *cur = cha->head;
120 + chanode_t *cur = cha->ancur;
121 while (cur) {
122 chanode_t *tmp = cur;
123 cur = cur->next;
@@ -142,7 +132,6 @@ typedef struct s_bdrecord {
132 } bdrecord_t;
133
134 typedef struct s_bdfile {
145 - const unsigned char *data, *top;
135 chastore_t cha;
136 unsigned int fphbits;
137 bdrecord_t **fphash;
@@ -152,7 +141,7 @@ static int delta_prepare(const unsigned char *buf, int bufsize, bdfile_t *bdf)
141 {
142 unsigned int fphbits;
143 int i, hsize;
155 - const unsigned char *base, *data, *top;
144 + const unsigned char *data, *top;
145 bdrecord_t *brec;
146 bdrecord_t **fphash;
147
@@ -165,13 +154,12 @@ static int delta_prepare(const unsigned char *buf, int bufsize, bdfile_t *bdf)
154 fphash[i] = NULL;
155 cha_init(&bdf->cha, sizeof(bdrecord_t), hsize / 4 + 1);
156
168 - bdf->data = data = base = buf;
169 - bdf->top = top = buf + bufsize;
170 - data += (bufsize / BLK_SIZE) * BLK_SIZE;
157 + top = buf + bufsize;
158 + data = buf + (bufsize / BLK_SIZE) * BLK_SIZE;
159 if (data == top)
160 data -= BLK_SIZE;
161
174 - for ( ; data >= base; data -= BLK_SIZE) {
162 + for ( ; data >= buf; data -= BLK_SIZE) {
163 brec = cha_alloc(&bdf->cha);
164 if (!brec) {
165 cha_free(&bdf->cha);
@@ -208,7 +196,7 @@ void *diff_delta(void *from_buf, unsigned long from_size,
196 {
197 int i, outpos, outsize, inscnt, csize, msize, moff;
198 unsigned int fp;
211 - const unsigned char *data, *top, *ptr1, *ptr2;
199 + const unsigned char *ref_data, *ref_top, *data, *top, *ptr1, *ptr2;
200 unsigned char *out, *orig;
201 bdrecord_t *brec;
202 bdfile_t bdf;
@@ -224,6 +212,8 @@ void *diff_delta(void *from_buf, unsigned long from_size,
212 return NULL;
213 }
214
215 + ref_data = from_buf;
216 + ref_top = from_buf + from_size;
217 data = to_buf;
218 top = to_buf + to_size;
219
@@ -253,7 +243,7 @@ void *diff_delta(void *from_buf, unsigned long from_size,
243 i = HASH(fp, bdf.fphbits);
244 for (brec = bdf.fphash[i]; brec; brec = brec->next) {
245 if (brec->fp == fp) {
256 - csize = bdf.top - brec->ptr;
246 + csize = ref_top - brec->ptr;
247 if (csize > top - data)
248 csize = top - data;
249 for (ptr1 = brec->ptr, ptr2 = data;
@@ -262,7 +252,7 @@ void *diff_delta(void *from_buf, unsigned long from_size,
252
253 csize = ptr1 - brec->ptr;
254 if (csize > msize) {
265 - moff = brec->ptr - bdf.data;
255 + moff = brec->ptr - ref_data;
256 msize = csize;
257 if (msize >= 0x10000) {
258 msize = 0x10000;