Skip to content

Commit b82dd3f

Browse files
phillipwoodgitster
authored andcommitted
xdiff: avoid unnecessary memory allocations
rindex and ha are only used by xdl_cleanup_records() which is not called by the histogram or patience algorithms. The perf test results show a small reduction in run time but that is probably within the noise. Test HEAD^ HEAD ----------------------------------------------------------------------------- 4000.1: log -3000 (baseline) 0.19(0.17+0.02) 0.19(0.12+0.07) +0.0% 4000.2: log --raw -3000 (tree-only) 0.98(0.78+0.20) 0.98(0.81+0.16) +0.0% 4000.3: log -p -3000 (Myers) 4.81(4.15+0.64) 4.81(4.23+0.56) +0.0% 4000.4: log -p -3000 --histogram 5.87(5.19+0.66) 5.83(5.11+0.70) -0.7% 4000.5: log -p -3000 --patience 5.35(4.60+0.73) 5.31(4.61+0.69) -0.7% Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 663c5ad commit b82dd3f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

xdiff/xprepare.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,13 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
213213
goto abort;
214214
memset(rchg, 0, (nrec + 2) * sizeof(char));
215215

216-
if (!(rindex = (long *) xdl_malloc((nrec + 1) * sizeof(long))))
217-
goto abort;
218-
if (!(ha = (unsigned long *) xdl_malloc((nrec + 1) * sizeof(unsigned long))))
219-
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+
}
220223

221224
xdf->nrec = nrec;
222225
xdf->recs = recs;

0 commit comments

Comments
 (0)