Git fork

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>

authored by

Ezekiel Newren and committed by
Junio C Hamano
5c294dce f4ea812b

+16 -21
+14 -10
xdiff/xdiffi.c
··· 22 22 23 23 #include "xinclude.h" 24 24 25 + static unsigned long get_hash(xdfile_t *xdf, long index) 26 + { 27 + return xdf->recs[xdf->rindex[index]]->ha; 28 + } 29 + 25 30 #define XDL_MAX_COST_MIN 256 26 31 #define XDL_HEUR_MIN_COST 256 27 32 #define XDL_LINE_MAX (long)((1UL << (CHAR_BIT * sizeof(long) - 1)) - 1) ··· 42 47 * using this algorithm, so a little bit of heuristic is needed to cut the 43 48 * search and to return a suboptimal point. 44 49 */ 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, 47 52 long *kvdf, long *kvdb, int need_min, xdpsplit_t *spl, 48 53 xdalgoenv_t *xenv) { 49 54 long dmin = off1 - lim2, dmax = lim1 - off2; ··· 87 92 i1 = kvdf[d + 1]; 88 93 prev1 = i1; 89 94 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++); 91 96 if (i1 - prev1 > xenv->snake_cnt) 92 97 got_snake = 1; 93 98 kvdf[d] = i1; ··· 124 129 i1 = kvdb[d + 1] - 1; 125 130 prev1 = i1; 126 131 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--); 128 133 if (prev1 - i1 > xenv->snake_cnt) 129 134 got_snake = 1; 130 135 kvdb[d] = i1; ··· 159 164 if (v > XDL_K_HEUR * ec && v > best && 160 165 off1 + xenv->snake_cnt <= i1 && i1 < lim1 && 161 166 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++) 163 168 if (k == xenv->snake_cnt) { 164 169 best = v; 165 170 spl->i1 = i1; ··· 183 188 if (v > XDL_K_HEUR * ec && v > best && 184 189 off1 < i1 && i1 <= lim1 - xenv->snake_cnt && 185 190 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++) 187 192 if (k == xenv->snake_cnt - 1) { 188 193 best = v; 189 194 spl->i1 = i1; ··· 260 265 int xdl_recs_cmp(xdfile_t *xdf1, long off1, long lim1, 261 266 xdfile_t *xdf2, long off2, long lim2, 262 267 long *kvdf, long *kvdb, int need_min, xdalgoenv_t *xenv) { 263 - unsigned long const *ha1 = xdf1->ha, *ha2 = xdf2->ha; 264 268 265 269 /* 266 270 * Shrink the box by walking through each diagonal snake (SW and NE). 267 271 */ 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--); 270 274 271 275 /* 272 276 * If one dimension is empty, then all records on the other one must ··· 285 289 /* 286 290 * Divide ... 287 291 */ 288 - if (xdl_split(ha1, off1, lim1, ha2, off2, lim2, kvdf, kvdb, 292 + if (xdl_split(xdf1, off1, lim1, xdf2, off2, lim2, kvdf, kvdb, 289 293 need_min, &spl, xenv) < 0) { 290 294 291 295 return -1;
+2 -10
xdiff/xprepare.c
··· 133 133 { 134 134 xdl_free(xdf->rindex); 135 135 xdl_free(xdf->rchg - 1); 136 - xdl_free(xdf->ha); 137 136 xdl_free(xdf->recs); 138 137 xdl_cha_free(&xdf->rcha); 139 138 } ··· 146 145 char const *blk, *cur, *top, *prev; 147 146 xrecord_t *crec; 148 147 149 - xdf->ha = NULL; 150 148 xdf->rindex = NULL; 151 149 xdf->rchg = NULL; 152 150 xdf->recs = NULL; ··· 180 178 if ((XDF_DIFF_ALG(xpp->flags) != XDF_PATIENCE_DIFF) && 181 179 (XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF)) { 182 180 if (!XDL_ALLOC_ARRAY(xdf->rindex, xdf->nrec + 1)) 183 - goto abort; 184 - if (!XDL_ALLOC_ARRAY(xdf->ha, xdf->nrec + 1)) 185 181 goto abort; 186 182 } 187 183 ··· 300 296 i <= xdf1->dend; i++, recs++) { 301 297 if (dis1[i] == 1 || 302 298 (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; 306 300 } else 307 301 xdf1->rchg[i] = 1; 308 302 } ··· 312 306 i <= xdf2->dend; i++, recs++) { 313 307 if (dis2[i] == 1 || 314 308 (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; 318 310 } else 319 311 xdf2->rchg[i] = 1; 320 312 }
-1
xdiff/xtypes.h
··· 52 52 char *rchg; 53 53 long *rindex; 54 54 long nreff; 55 - unsigned long *ha; 56 55 } xdfile_t; 57 56 58 57 typedef struct s_xdfenv {