mirror of
https://github.com/git-for-windows/git.git
synced 2026-04-27 18:11:59 -05:00
Merge branch 'en/xdiff-cleanup-3' into seen
Preparation of the xdiff/ codebase to work with Rust. * en/xdiff-cleanup-3: xdiff/xdl_cleanup_records: put braces around the else clause xdiff/xdl_cleanup_records: make setting action easier to follow xdiff/xdl_cleanup_records: make limits more clear xdiff/xdl_cleanup_records: use unambiguous types xdiff: use unambiguous types in xdl_bogo_sqrt() xdiff/xdl_cleanup_records: delete local recs pointer
This commit is contained in:
@@ -348,7 +348,7 @@ int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
|
||||
kvdf += xe->xdf2.nreff + 1;
|
||||
kvdb += xe->xdf2.nreff + 1;
|
||||
|
||||
xenv.mxcost = xdl_bogosqrt(ndiags);
|
||||
xenv.mxcost = (long)xdl_bogosqrt((uint64_t)ndiags);
|
||||
if (xenv.mxcost < XDL_MAX_COST_MIN)
|
||||
xenv.mxcost = XDL_MAX_COST_MIN;
|
||||
xenv.snake_cnt = XDL_SNAKE_CNT;
|
||||
|
||||
@@ -197,8 +197,8 @@ void xdl_free_env(xdfenv_t *xe) {
|
||||
}
|
||||
|
||||
|
||||
static bool xdl_clean_mmatch(uint8_t const *action, long i, long s, long e) {
|
||||
long r, rdis0, rpdis0, rdis1, rpdis1;
|
||||
static bool xdl_clean_mmatch(uint8_t const *action, ptrdiff_t i, ptrdiff_t s, ptrdiff_t e) {
|
||||
ptrdiff_t r, rdis0, rpdis0, rdis1, rpdis1;
|
||||
|
||||
/*
|
||||
* Limits the window that is examined during the similar-lines
|
||||
@@ -268,8 +268,7 @@ static bool xdl_clean_mmatch(uint8_t const *action, long i, long s, long e) {
|
||||
* might be potentially discarded if they appear in a run of discardable.
|
||||
*/
|
||||
static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2) {
|
||||
long i, nm, mlim;
|
||||
xrecord_t *recs;
|
||||
ptrdiff_t i, nm, mlim1, mlim2;
|
||||
xdlclass_t *rcrec;
|
||||
uint8_t *action1 = NULL, *action2 = NULL;
|
||||
bool need_min = !!(cf->flags & XDF_NEED_MINIMAL);
|
||||
@@ -288,23 +287,40 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (need_min) {
|
||||
/* i.e. infinity */
|
||||
mlim1 = PTRDIFF_MAX;
|
||||
mlim2 = PTRDIFF_MAX;
|
||||
} else {
|
||||
mlim1 = XDL_MIN(xdl_bogosqrt(xdf1->nrec), XDL_MAX_EQLIMIT);
|
||||
mlim2 = XDL_MIN(xdl_bogosqrt(xdf2->nrec), XDL_MAX_EQLIMIT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize temporary arrays with DISCARD, KEEP, or INVESTIGATE.
|
||||
*/
|
||||
if ((mlim = xdl_bogosqrt((long)xdf1->nrec)) > XDL_MAX_EQLIMIT)
|
||||
mlim = XDL_MAX_EQLIMIT;
|
||||
for (i = xdf1->dstart, recs = &xdf1->recs[xdf1->dstart]; i <= xdf1->dend; i++, recs++) {
|
||||
rcrec = cf->rcrecs[recs->minimal_perfect_hash];
|
||||
for (i = xdf1->dstart; i <= xdf1->dend; i++) {
|
||||
size_t mph1 = xdf1->recs[i].minimal_perfect_hash;
|
||||
rcrec = cf->rcrecs[mph1];
|
||||
nm = rcrec ? rcrec->len2 : 0;
|
||||
action1[i] = (nm == 0) ? DISCARD: (nm >= mlim && !need_min) ? INVESTIGATE: KEEP;
|
||||
if (nm == 0)
|
||||
action1[i] = DISCARD;
|
||||
else if (nm < mlim1)
|
||||
action1[i] = KEEP;
|
||||
else /* nm >= mlim1 */
|
||||
action1[i] = INVESTIGATE;
|
||||
}
|
||||
|
||||
if ((mlim = xdl_bogosqrt((long)xdf2->nrec)) > XDL_MAX_EQLIMIT)
|
||||
mlim = XDL_MAX_EQLIMIT;
|
||||
for (i = xdf2->dstart, recs = &xdf2->recs[xdf2->dstart]; i <= xdf2->dend; i++, recs++) {
|
||||
rcrec = cf->rcrecs[recs->minimal_perfect_hash];
|
||||
for (i = xdf2->dstart; i <= xdf2->dend; i++) {
|
||||
size_t mph2 = xdf2->recs[i].minimal_perfect_hash;
|
||||
rcrec = cf->rcrecs[mph2];
|
||||
nm = rcrec ? rcrec->len1 : 0;
|
||||
action2[i] = (nm == 0) ? DISCARD: (nm >= mlim && !need_min) ? INVESTIGATE: KEEP;
|
||||
if (nm == 0)
|
||||
action2[i] = DISCARD;
|
||||
else if (nm < mlim2)
|
||||
action2[i] = KEEP;
|
||||
else /* nm >= mlim2 */
|
||||
action2[i] = INVESTIGATE;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -312,27 +328,27 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
|
||||
* false, or become true.
|
||||
*/
|
||||
xdf1->nreff = 0;
|
||||
for (i = xdf1->dstart, recs = &xdf1->recs[xdf1->dstart];
|
||||
i <= xdf1->dend; i++, recs++) {
|
||||
for (i = xdf1->dstart; i <= xdf1->dend; i++) {
|
||||
if (action1[i] == KEEP ||
|
||||
(action1[i] == INVESTIGATE && !xdl_clean_mmatch(action1, i, xdf1->dstart, xdf1->dend))) {
|
||||
xdf1->reference_index[xdf1->nreff++] = i;
|
||||
/* changed[i] remains false, i.e. keep */
|
||||
} else
|
||||
} else {
|
||||
xdf1->changed[i] = true;
|
||||
/* i.e. discard */
|
||||
}
|
||||
}
|
||||
|
||||
xdf2->nreff = 0;
|
||||
for (i = xdf2->dstart, recs = &xdf2->recs[xdf2->dstart];
|
||||
i <= xdf2->dend; i++, recs++) {
|
||||
for (i = xdf2->dstart; i <= xdf2->dend; i++) {
|
||||
if (action2[i] == KEEP ||
|
||||
(action2[i] == INVESTIGATE && !xdl_clean_mmatch(action2, i, xdf2->dstart, xdf2->dend))) {
|
||||
xdf2->reference_index[xdf2->nreff++] = i;
|
||||
/* changed[i] remains false, i.e. keep */
|
||||
} else
|
||||
} else {
|
||||
xdf2->changed[i] = true;
|
||||
/* i.e. discard */
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
#include "xinclude.h"
|
||||
|
||||
|
||||
long xdl_bogosqrt(long n) {
|
||||
long i;
|
||||
uint64_t xdl_bogosqrt(uint64_t n) {
|
||||
uint64_t i;
|
||||
|
||||
/*
|
||||
* Classical integer square root approximation using shifts.
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
|
||||
|
||||
long xdl_bogosqrt(long n);
|
||||
uint64_t xdl_bogosqrt(uint64_t n);
|
||||
int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize,
|
||||
xdemitcb_t *ecb);
|
||||
int xdl_cha_init(chastore_t *cha, long isize, long icount);
|
||||
|
||||
Reference in New Issue
Block a user