@@ -197,8 +197,8 @@ void xdl_free_env(xdfenv_t *xe) {
197197}
198198
199199
200- static bool xdl_clean_mmatch (uint8_t const * action , long i , long s , long e ) {
201- long r , rdis0 , rpdis0 , rdis1 , rpdis1 ;
200+ static bool xdl_clean_mmatch (uint8_t const * action , ptrdiff_t i , ptrdiff_t s , ptrdiff_t e ) {
201+ ptrdiff_t r , rdis0 , rpdis0 , rdis1 , rpdis1 ;
202202
203203 /*
204204 * 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) {
268268 * might be potentially discarded if they appear in a run of discardable.
269269 */
270270static int xdl_cleanup_records (xdlclassifier_t * cf , xdfile_t * xdf1 , xdfile_t * xdf2 ) {
271- long i , nm , mlim ;
272- xrecord_t * recs ;
271+ ptrdiff_t i , nm , mlim1 , mlim2 ;
273272 xdlclass_t * rcrec ;
274273 uint8_t * action1 = NULL , * action2 = NULL ;
275274 bool need_min = !!(cf -> flags & XDF_NEED_MINIMAL );
@@ -288,51 +287,68 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
288287 goto cleanup ;
289288 }
290289
290+ if (need_min ) {
291+ /* i.e. infinity */
292+ mlim1 = PTRDIFF_MAX ;
293+ mlim2 = PTRDIFF_MAX ;
294+ } else {
295+ mlim1 = XDL_MIN (xdl_bogosqrt (xdf1 -> nrec ), XDL_MAX_EQLIMIT );
296+ mlim2 = XDL_MIN (xdl_bogosqrt (xdf2 -> nrec ), XDL_MAX_EQLIMIT );
297+ }
298+
291299 /*
292300 * Initialize temporary arrays with DISCARD, KEEP, or INVESTIGATE.
293301 */
294- if ((mlim = xdl_bogosqrt ((long )xdf1 -> nrec )) > XDL_MAX_EQLIMIT )
295- mlim = XDL_MAX_EQLIMIT ;
296- for (i = xdf1 -> dstart , recs = & xdf1 -> recs [xdf1 -> dstart ]; i <= xdf1 -> dend ; i ++ , recs ++ ) {
297- rcrec = cf -> rcrecs [recs -> minimal_perfect_hash ];
302+ for (i = xdf1 -> dstart ; i <= xdf1 -> dend ; i ++ ) {
303+ size_t mph1 = xdf1 -> recs [i ].minimal_perfect_hash ;
304+ rcrec = cf -> rcrecs [mph1 ];
298305 nm = rcrec ? rcrec -> len2 : 0 ;
299- action1 [i ] = (nm == 0 ) ? DISCARD : (nm >= mlim && !need_min ) ? INVESTIGATE : KEEP ;
306+ if (nm == 0 )
307+ action1 [i ] = DISCARD ;
308+ else if (nm < mlim1 )
309+ action1 [i ] = KEEP ;
310+ else /* nm >= mlim1 */
311+ action1 [i ] = INVESTIGATE ;
300312 }
301313
302- if ((mlim = xdl_bogosqrt ((long )xdf2 -> nrec )) > XDL_MAX_EQLIMIT )
303- mlim = XDL_MAX_EQLIMIT ;
304- for (i = xdf2 -> dstart , recs = & xdf2 -> recs [xdf2 -> dstart ]; i <= xdf2 -> dend ; i ++ , recs ++ ) {
305- rcrec = cf -> rcrecs [recs -> minimal_perfect_hash ];
314+ for (i = xdf2 -> dstart ; i <= xdf2 -> dend ; i ++ ) {
315+ size_t mph2 = xdf2 -> recs [i ].minimal_perfect_hash ;
316+ rcrec = cf -> rcrecs [mph2 ];
306317 nm = rcrec ? rcrec -> len1 : 0 ;
307- action2 [i ] = (nm == 0 ) ? DISCARD : (nm >= mlim && !need_min ) ? INVESTIGATE : KEEP ;
318+ if (nm == 0 )
319+ action2 [i ] = DISCARD ;
320+ else if (nm < mlim2 )
321+ action2 [i ] = KEEP ;
322+ else /* nm >= mlim2 */
323+ action2 [i ] = INVESTIGATE ;
308324 }
309325
310326 /*
311327 * Use temporary arrays to decide if changed[i] should remain
312328 * false, or become true.
313329 */
314330 xdf1 -> nreff = 0 ;
315- for (i = xdf1 -> dstart , recs = & xdf1 -> recs [xdf1 -> dstart ];
316- i <= xdf1 -> dend ; i ++ , recs ++ ) {
331+ for (i = xdf1 -> dstart ; i <= xdf1 -> dend ; i ++ ) {
317332 if (action1 [i ] == KEEP ||
318333 (action1 [i ] == INVESTIGATE && !xdl_clean_mmatch (action1 , i , xdf1 -> dstart , xdf1 -> dend ))) {
319334 xdf1 -> reference_index [xdf1 -> nreff ++ ] = i ;
320335 /* changed[i] remains false, i.e. keep */
321- } else
336+ } else {
322337 xdf1 -> changed [i ] = true;
323338 /* i.e. discard */
339+ }
324340 }
325341
326342 xdf2 -> nreff = 0 ;
327- for (i = xdf2 -> dstart , recs = & xdf2 -> recs [xdf2 -> dstart ];
328- i <= xdf2 -> dend ; i ++ , recs ++ ) {
343+ for (i = xdf2 -> dstart ; i <= xdf2 -> dend ; i ++ ) {
329344 if (action2 [i ] == KEEP ||
330345 (action2 [i ] == INVESTIGATE && !xdl_clean_mmatch (action2 , i , xdf2 -> dstart , xdf2 -> dend ))) {
331346 xdf2 -> reference_index [xdf2 -> nreff ++ ] = i ;
332347 /* changed[i] remains false, i.e. keep */
333- } else
348+ } else {
334349 xdf2 -> changed [i ] = true;
335350 /* i.e. discard */
351+ }
336352 }
337353
338354cleanup :
0 commit comments