Skip to content

Commit 5c294dc

Browse files
ezekielnewrengitster
authored andcommitted
xdiff: delete redundant array xdfile_t.ha
When 0 <= i < xdfile_t.nreff the following is true: xdfile_t.ha[i] == xdfile_t.recs[xdfile_t.rindex[i]] This makes the code about 5% slower. The fields rindex and ha are specific to the classic diff (myers and minimal). I plan on creating a struct for classic diff, but there's a lot of cleanup that needs to be done before that can happen and leaving ha in would make those cleanups harder to follow. A subsequent commit will delete the chastore cha from xdfile_t. That later commit will investigate deleting ha and cha independently and together. Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f4ea812 commit 5c294dc

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

xdiff/xdiffi.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222

2323
#include "xinclude.h"
2424

25+
static unsigned long get_hash(xdfile_t *xdf, long index)
26+
{
27+
return xdf->recs[xdf->rindex[index]]->ha;
28+
}
29+
2530
#define XDL_MAX_COST_MIN 256
2631
#define XDL_HEUR_MIN_COST 256
2732
#define XDL_LINE_MAX (long)((1UL << (CHAR_BIT * sizeof(long) - 1)) - 1)
@@ -42,8 +47,8 @@ typedef struct s_xdpsplit {
4247
* using this algorithm, so a little bit of heuristic is needed to cut the
4348
* search and to return a suboptimal point.
4449
*/
45-
static long xdl_split(unsigned long const *ha1, long off1, long lim1,
46-
unsigned long const *ha2, long off2, long lim2,
50+
static long xdl_split(xdfile_t *xdf1, long off1, long lim1,
51+
xdfile_t *xdf2, long off2, long lim2,
4752
long *kvdf, long *kvdb, int need_min, xdpsplit_t *spl,
4853
xdalgoenv_t *xenv) {
4954
long dmin = off1 - lim2, dmax = lim1 - off2;
@@ -87,7 +92,7 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
8792
i1 = kvdf[d + 1];
8893
prev1 = i1;
8994
i2 = i1 - d;
90-
for (; i1 < lim1 && i2 < lim2 && ha1[i1] == ha2[i2]; i1++, i2++);
95+
for (; i1 < lim1 && i2 < lim2 && get_hash(xdf1, i1) == get_hash(xdf2, i2); i1++, i2++);
9196
if (i1 - prev1 > xenv->snake_cnt)
9297
got_snake = 1;
9398
kvdf[d] = i1;
@@ -124,7 +129,7 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
124129
i1 = kvdb[d + 1] - 1;
125130
prev1 = i1;
126131
i2 = i1 - d;
127-
for (; i1 > off1 && i2 > off2 && ha1[i1 - 1] == ha2[i2 - 1]; i1--, i2--);
132+
for (; i1 > off1 && i2 > off2 && get_hash(xdf1, i1 - 1) == get_hash(xdf2, i2 - 1); i1--, i2--);
128133
if (prev1 - i1 > xenv->snake_cnt)
129134
got_snake = 1;
130135
kvdb[d] = i1;
@@ -159,7 +164,7 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
159164
if (v > XDL_K_HEUR * ec && v > best &&
160165
off1 + xenv->snake_cnt <= i1 && i1 < lim1 &&
161166
off2 + xenv->snake_cnt <= i2 && i2 < lim2) {
162-
for (k = 1; ha1[i1 - k] == ha2[i2 - k]; k++)
167+
for (k = 1; get_hash(xdf1, i1 - k) == get_hash(xdf2, i2 - k); k++)
163168
if (k == xenv->snake_cnt) {
164169
best = v;
165170
spl->i1 = i1;
@@ -183,7 +188,7 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
183188
if (v > XDL_K_HEUR * ec && v > best &&
184189
off1 < i1 && i1 <= lim1 - xenv->snake_cnt &&
185190
off2 < i2 && i2 <= lim2 - xenv->snake_cnt) {
186-
for (k = 0; ha1[i1 + k] == ha2[i2 + k]; k++)
191+
for (k = 0; get_hash(xdf1, i1 + k) == get_hash(xdf2, i2 + k); k++)
187192
if (k == xenv->snake_cnt - 1) {
188193
best = v;
189194
spl->i1 = i1;
@@ -260,13 +265,12 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
260265
int xdl_recs_cmp(xdfile_t *xdf1, long off1, long lim1,
261266
xdfile_t *xdf2, long off2, long lim2,
262267
long *kvdf, long *kvdb, int need_min, xdalgoenv_t *xenv) {
263-
unsigned long const *ha1 = xdf1->ha, *ha2 = xdf2->ha;
264268

265269
/*
266270
* Shrink the box by walking through each diagonal snake (SW and NE).
267271
*/
268-
for (; off1 < lim1 && off2 < lim2 && ha1[off1] == ha2[off2]; off1++, off2++);
269-
for (; off1 < lim1 && off2 < lim2 && ha1[lim1 - 1] == ha2[lim2 - 1]; lim1--, lim2--);
272+
for (; off1 < lim1 && off2 < lim2 && get_hash(xdf1, off1) == get_hash(xdf2, off2); off1++, off2++);
273+
for (; off1 < lim1 && off2 < lim2 && get_hash(xdf1, lim1 - 1) == get_hash(xdf2, lim2 - 1); lim1--, lim2--);
270274

271275
/*
272276
* If one dimension is empty, then all records on the other one must
@@ -285,7 +289,7 @@ int xdl_recs_cmp(xdfile_t *xdf1, long off1, long lim1,
285289
/*
286290
* Divide ...
287291
*/
288-
if (xdl_split(ha1, off1, lim1, ha2, off2, lim2, kvdf, kvdb,
292+
if (xdl_split(xdf1, off1, lim1, xdf2, off2, lim2, kvdf, kvdb,
289293
need_min, &spl, xenv) < 0) {
290294

291295
return -1;

xdiff/xprepare.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ static void xdl_free_ctx(xdfile_t *xdf)
133133
{
134134
xdl_free(xdf->rindex);
135135
xdl_free(xdf->rchg - 1);
136-
xdl_free(xdf->ha);
137136
xdl_free(xdf->recs);
138137
xdl_cha_free(&xdf->rcha);
139138
}
@@ -146,7 +145,6 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
146145
char const *blk, *cur, *top, *prev;
147146
xrecord_t *crec;
148147

149-
xdf->ha = NULL;
150148
xdf->rindex = NULL;
151149
xdf->rchg = NULL;
152150
xdf->recs = NULL;
@@ -181,8 +179,6 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
181179
(XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF)) {
182180
if (!XDL_ALLOC_ARRAY(xdf->rindex, xdf->nrec + 1))
183181
goto abort;
184-
if (!XDL_ALLOC_ARRAY(xdf->ha, xdf->nrec + 1))
185-
goto abort;
186182
}
187183

188184
xdf->rchg += 1;
@@ -300,9 +296,7 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
300296
i <= xdf1->dend; i++, recs++) {
301297
if (dis1[i] == 1 ||
302298
(dis1[i] == 2 && !xdl_clean_mmatch(dis1, i, xdf1->dstart, xdf1->dend))) {
303-
xdf1->rindex[nreff] = i;
304-
xdf1->ha[nreff] = (*recs)->ha;
305-
nreff++;
299+
xdf1->rindex[nreff++] = i;
306300
} else
307301
xdf1->rchg[i] = 1;
308302
}
@@ -312,9 +306,7 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
312306
i <= xdf2->dend; i++, recs++) {
313307
if (dis2[i] == 1 ||
314308
(dis2[i] == 2 && !xdl_clean_mmatch(dis2, i, xdf2->dstart, xdf2->dend))) {
315-
xdf2->rindex[nreff] = i;
316-
xdf2->ha[nreff] = (*recs)->ha;
317-
nreff++;
309+
xdf2->rindex[nreff++] = i;
318310
} else
319311
xdf2->rchg[i] = 1;
320312
}

xdiff/xtypes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ typedef struct s_xdfile {
5252
char *rchg;
5353
long *rindex;
5454
long nreff;
55-
unsigned long *ha;
5655
} xdfile_t;
5756

5857
typedef struct s_xdfenv {

0 commit comments

Comments
 (0)