Skip to content

Commit a0f5ca9

Browse files
committed
Merge branch 'pw/xdiff-classify-record-in-histogram'
"diff --histogram" optimization. * pw/xdiff-classify-record-in-histogram: xdiff: drop unused flags parameter from recs_match xdiff: drop xpparam_t parameter from histogram cmp_recs() xdiff: drop CMP_ENV macro from xhistogram xdiff: simplify comparison xdiff: avoid unnecessary memory allocations diff histogram: intern strings
2 parents 69a9c10 + 1e45db1 commit a0f5ca9

File tree

3 files changed

+29
-42
lines changed

3 files changed

+29
-42
lines changed

xdiff/xdiffi.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,9 @@ static xdchange_t *xdl_add_change(xdchange_t *xscr, long i1, long i2, long chg1,
390390
}
391391

392392

393-
static int recs_match(xrecord_t *rec1, xrecord_t *rec2, long flags)
393+
static int recs_match(xrecord_t *rec1, xrecord_t *rec2)
394394
{
395-
return (rec1->ha == rec2->ha &&
396-
xdl_recmatch(rec1->ptr, rec1->size,
397-
rec2->ptr, rec2->size,
398-
flags));
395+
return (rec1->ha == rec2->ha);
399396
}
400397

401398
/*
@@ -759,10 +756,10 @@ static inline int group_previous(xdfile_t *xdf, struct xdlgroup *g)
759756
* following group, expand this group to include it. Return 0 on success or -1
760757
* if g cannot be slid down.
761758
*/
762-
static int group_slide_down(xdfile_t *xdf, struct xdlgroup *g, long flags)
759+
static int group_slide_down(xdfile_t *xdf, struct xdlgroup *g)
763760
{
764761
if (g->end < xdf->nrec &&
765-
recs_match(xdf->recs[g->start], xdf->recs[g->end], flags)) {
762+
recs_match(xdf->recs[g->start], xdf->recs[g->end])) {
766763
xdf->rchg[g->start++] = 0;
767764
xdf->rchg[g->end++] = 1;
768765

@@ -780,10 +777,10 @@ static int group_slide_down(xdfile_t *xdf, struct xdlgroup *g, long flags)
780777
* into a previous group, expand this group to include it. Return 0 on success
781778
* or -1 if g cannot be slid up.
782779
*/
783-
static int group_slide_up(xdfile_t *xdf, struct xdlgroup *g, long flags)
780+
static int group_slide_up(xdfile_t *xdf, struct xdlgroup *g)
784781
{
785782
if (g->start > 0 &&
786-
recs_match(xdf->recs[g->start - 1], xdf->recs[g->end - 1], flags)) {
783+
recs_match(xdf->recs[g->start - 1], xdf->recs[g->end - 1])) {
787784
xdf->rchg[--g->start] = 1;
788785
xdf->rchg[--g->end] = 0;
789786

@@ -833,7 +830,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
833830
end_matching_other = -1;
834831

835832
/* Shift the group backward as much as possible: */
836-
while (!group_slide_up(xdf, &g, flags))
833+
while (!group_slide_up(xdf, &g))
837834
if (group_previous(xdfo, &go))
838835
BUG("group sync broken sliding up");
839836

@@ -848,7 +845,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
848845

849846
/* Now shift the group forward as far as possible: */
850847
while (1) {
851-
if (group_slide_down(xdf, &g, flags))
848+
if (group_slide_down(xdf, &g))
852849
break;
853850
if (group_next(xdfo, &go))
854851
BUG("group sync broken sliding down");
@@ -875,7 +872,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
875872
* other file that it can align with.
876873
*/
877874
while (go.end == go.start) {
878-
if (group_slide_up(xdf, &g, flags))
875+
if (group_slide_up(xdf, &g))
879876
BUG("match disappeared");
880877
if (group_previous(xdfo, &go))
881878
BUG("group sync broken sliding to match");
@@ -918,7 +915,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
918915
}
919916

920917
while (g.end > best_shift) {
921-
if (group_slide_up(xdf, &g, flags))
918+
if (group_slide_up(xdf, &g))
922919
BUG("best shift unreached");
923920
if (group_previous(xdfo, &go))
924921
BUG("group sync broken sliding to blank line");

xdiff/xhistogram.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,14 @@ struct region {
8888
#define REC(env, s, l) \
8989
(env->xdf##s.recs[l - 1])
9090

91-
static int cmp_recs(xpparam_t const *xpp,
92-
xrecord_t *r1, xrecord_t *r2)
91+
static int cmp_recs(xrecord_t *r1, xrecord_t *r2)
9392
{
94-
return r1->ha == r2->ha &&
95-
xdl_recmatch(r1->ptr, r1->size, r2->ptr, r2->size,
96-
xpp->flags);
97-
}
93+
return r1->ha == r2->ha;
9894

99-
#define CMP_ENV(xpp, env, s1, l1, s2, l2) \
100-
(cmp_recs(xpp, REC(env, s1, l1), REC(env, s2, l2)))
95+
}
10196

10297
#define CMP(i, s1, l1, s2, l2) \
103-
(cmp_recs(i->xpp, REC(i->env, s1, l1), REC(i->env, s2, l2)))
98+
(cmp_recs(REC(i->env, s1, l1), REC(i->env, s2, l2)))
10499

105100
#define TABLE_HASH(index, side, line) \
106101
XDL_HASHLONG((REC(index->env, side, line))->ha, index->table_bits)

xdiff/xprepare.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,11 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
181181
if (!(recs = (xrecord_t **) xdl_malloc(narec * sizeof(xrecord_t *))))
182182
goto abort;
183183

184-
if (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF)
185-
hbits = hsize = 0;
186-
else {
187-
hbits = xdl_hashbits((unsigned int) narec);
188-
hsize = 1 << hbits;
189-
if (!(rhash = (xrecord_t **) xdl_malloc(hsize * sizeof(xrecord_t *))))
190-
goto abort;
191-
memset(rhash, 0, hsize * sizeof(xrecord_t *));
192-
}
184+
hbits = xdl_hashbits((unsigned int) narec);
185+
hsize = 1 << hbits;
186+
if (!(rhash = (xrecord_t **) xdl_malloc(hsize * sizeof(xrecord_t *))))
187+
goto abort;
188+
memset(rhash, 0, hsize * sizeof(xrecord_t *));
193189

194190
nrec = 0;
195191
if ((cur = blk = xdl_mmfile_first(mf, &bsize)) != NULL) {
@@ -208,9 +204,7 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
208204
crec->size = (long) (cur - prev);
209205
crec->ha = hav;
210206
recs[nrec++] = crec;
211-
212-
if ((XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF) &&
213-
xdl_classify_record(pass, cf, rhash, hbits, crec) < 0)
207+
if (xdl_classify_record(pass, cf, rhash, hbits, crec) < 0)
214208
goto abort;
215209
}
216210
}
@@ -219,10 +213,13 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
219213
goto abort;
220214
memset(rchg, 0, (nrec + 2) * sizeof(char));
221215

222-
if (!(rindex = (long *) xdl_malloc((nrec + 1) * sizeof(long))))
223-
goto abort;
224-
if (!(ha = (unsigned long *) xdl_malloc((nrec + 1) * sizeof(unsigned long))))
225-
goto abort;
216+
if ((XDF_DIFF_ALG(xpp->flags) != XDF_PATIENCE_DIFF) &&
217+
(XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF)) {
218+
if (!(rindex = xdl_malloc((nrec + 1) * sizeof(*rindex))))
219+
goto abort;
220+
if (!(ha = xdl_malloc((nrec + 1) * sizeof(*ha))))
221+
goto abort;
222+
}
226223

227224
xdf->nrec = nrec;
228225
xdf->recs = recs;
@@ -279,8 +276,7 @@ int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
279276
enl1 = xdl_guess_lines(mf1, sample) + 1;
280277
enl2 = xdl_guess_lines(mf2, sample) + 1;
281278

282-
if (XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF &&
283-
xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0)
279+
if (xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0)
284280
return -1;
285281

286282
if (xdl_prepare_ctx(1, mf1, enl1, xpp, &cf, &xe->xdf1) < 0) {
@@ -305,8 +301,7 @@ int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
305301
return -1;
306302
}
307303

308-
if (XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF)
309-
xdl_free_classifier(&cf);
304+
xdl_free_classifier(&cf);
310305

311306
return 0;
312307
}

0 commit comments

Comments
 (0)