Skip to content

Commit 9f37c27

Browse files
rctaygitster
authored andcommitted
xdiff/xprepare: skip classification
xdiff performs "classification" of records (xdl_classify_record()), replacing hashes (xrecord_t.ha) with a unique identifier of the record/line and building a hash table (xrecord_t.rhash) of records. This is then used to "cleanup" records (xdl_cleanup_records()). We don't need any of that in histogram diff, so we omit calls to these functions. We also skip allocating memory to the hash table, rhash, as it is no longer used. This gives us a small boost in performance. Signed-off-by: Tay Ray Chuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8c912ee commit 9f37c27

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

xdiff/xprepare.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,15 @@ static int xdl_prepare_ctx(mmfile_t *mf, long narec, xpparam_t const *xpp,
154154
if (!(recs = (xrecord_t **) xdl_malloc(narec * sizeof(xrecord_t *))))
155155
goto abort;
156156

157-
hbits = xdl_hashbits((unsigned int) narec);
158-
hsize = 1 << hbits;
159-
if (!(rhash = (xrecord_t **) xdl_malloc(hsize * sizeof(xrecord_t *))))
160-
goto abort;
161-
memset(rhash, 0, hsize * sizeof(xrecord_t *));
157+
if (xpp->flags & XDF_HISTOGRAM_DIFF)
158+
hbits = hsize = 0;
159+
else {
160+
hbits = xdl_hashbits((unsigned int) narec);
161+
hsize = 1 << hbits;
162+
if (!(rhash = (xrecord_t **) xdl_malloc(hsize * sizeof(xrecord_t *))))
163+
goto abort;
164+
memset(rhash, 0, hsize * sizeof(xrecord_t *));
165+
}
162166

163167
nrec = 0;
164168
if ((cur = blk = xdl_mmfile_first(mf, &bsize)) != NULL) {
@@ -183,7 +187,8 @@ static int xdl_prepare_ctx(mmfile_t *mf, long narec, xpparam_t const *xpp,
183187
crec->ha = hav;
184188
recs[nrec++] = crec;
185189

186-
if (xdl_classify_record(cf, rhash, hbits, crec) < 0)
190+
if (!(xpp->flags & XDF_HISTOGRAM_DIFF) &&
191+
xdl_classify_record(cf, rhash, hbits, crec) < 0)
187192
goto abort;
188193
}
189194
}
@@ -240,7 +245,8 @@ int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
240245
enl1 = xdl_guess_lines(mf1) + 1;
241246
enl2 = xdl_guess_lines(mf2) + 1;
242247

243-
if (xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0) {
248+
if (!(xpp->flags & XDF_HISTOGRAM_DIFF) &&
249+
xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0) {
244250

245251
return -1;
246252
}
@@ -257,9 +263,11 @@ int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
257263
return -1;
258264
}
259265

260-
xdl_free_classifier(&cf);
266+
if (!(xpp->flags & XDF_HISTOGRAM_DIFF))
267+
xdl_free_classifier(&cf);
261268

262269
if (!(xpp->flags & XDF_PATIENCE_DIFF) &&
270+
!(xpp->flags & XDF_HISTOGRAM_DIFF) &&
263271
xdl_optimize_ctxs(&xe->xdf1, &xe->xdf2) < 0) {
264272

265273
xdl_free_ctx(&xe->xdf2);

0 commit comments

Comments
 (0)