@@ -53,21 +53,6 @@ typedef struct s_xdlclassifier {
5353
5454
5555
56- static int xdl_init_classifier (xdlclassifier_t * cf , long size , long flags );
57- static void xdl_free_classifier (xdlclassifier_t * cf );
58- static int xdl_classify_record (unsigned int pass , xdlclassifier_t * cf , xrecord_t * * rhash ,
59- unsigned int hbits , xrecord_t * rec );
60- static int xdl_prepare_ctx (unsigned int pass , mmfile_t * mf , long narec , xpparam_t const * xpp ,
61- xdlclassifier_t * cf , xdfile_t * xdf );
62- static void xdl_free_ctx (xdfile_t * xdf );
63- static int xdl_clean_mmatch (char const * dis , long i , long s , long e );
64- static int xdl_cleanup_records (xdlclassifier_t * cf , xdfile_t * xdf1 , xdfile_t * xdf2 );
65- static int xdl_trim_ends (xdfile_t * xdf1 , xdfile_t * xdf2 );
66- static int xdl_optimize_ctxs (xdlclassifier_t * cf , xdfile_t * xdf1 , xdfile_t * xdf2 );
67-
68-
69-
70-
7156static int xdl_init_classifier (xdlclassifier_t * cf , long size , long flags ) {
7257 cf -> flags = flags ;
7358
@@ -242,57 +227,6 @@ static void xdl_free_ctx(xdfile_t *xdf) {
242227}
243228
244229
245- int xdl_prepare_env (mmfile_t * mf1 , mmfile_t * mf2 , xpparam_t const * xpp ,
246- xdfenv_t * xe ) {
247- long enl1 , enl2 , sample ;
248- xdlclassifier_t cf ;
249-
250- memset (& cf , 0 , sizeof (cf ));
251-
252- /*
253- * For histogram diff, we can afford a smaller sample size and
254- * thus a poorer estimate of the number of lines, as the hash
255- * table (rhash) won't be filled up/grown. The number of lines
256- * (nrecs) will be updated correctly anyway by
257- * xdl_prepare_ctx().
258- */
259- sample = (XDF_DIFF_ALG (xpp -> flags ) == XDF_HISTOGRAM_DIFF
260- ? XDL_GUESS_NLINES2 : XDL_GUESS_NLINES1 );
261-
262- enl1 = xdl_guess_lines (mf1 , sample ) + 1 ;
263- enl2 = xdl_guess_lines (mf2 , sample ) + 1 ;
264-
265- if (xdl_init_classifier (& cf , enl1 + enl2 + 1 , xpp -> flags ) < 0 )
266- return -1 ;
267-
268- if (xdl_prepare_ctx (1 , mf1 , enl1 , xpp , & cf , & xe -> xdf1 ) < 0 ) {
269-
270- xdl_free_classifier (& cf );
271- return -1 ;
272- }
273- if (xdl_prepare_ctx (2 , mf2 , enl2 , xpp , & cf , & xe -> xdf2 ) < 0 ) {
274-
275- xdl_free_ctx (& xe -> xdf1 );
276- xdl_free_classifier (& cf );
277- return -1 ;
278- }
279-
280- if ((XDF_DIFF_ALG (xpp -> flags ) != XDF_PATIENCE_DIFF ) &&
281- (XDF_DIFF_ALG (xpp -> flags ) != XDF_HISTOGRAM_DIFF ) &&
282- xdl_optimize_ctxs (& cf , & xe -> xdf1 , & xe -> xdf2 ) < 0 ) {
283-
284- xdl_free_ctx (& xe -> xdf2 );
285- xdl_free_ctx (& xe -> xdf1 );
286- xdl_free_classifier (& cf );
287- return -1 ;
288- }
289-
290- xdl_free_classifier (& cf );
291-
292- return 0 ;
293- }
294-
295-
296230void xdl_free_env (xdfenv_t * xe ) {
297231
298232 xdl_free_ctx (& xe -> xdf2 );
@@ -460,3 +394,53 @@ static int xdl_optimize_ctxs(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2
460394
461395 return 0 ;
462396}
397+
398+ int xdl_prepare_env (mmfile_t * mf1 , mmfile_t * mf2 , xpparam_t const * xpp ,
399+ xdfenv_t * xe ) {
400+ long enl1 , enl2 , sample ;
401+ xdlclassifier_t cf ;
402+
403+ memset (& cf , 0 , sizeof (cf ));
404+
405+ /*
406+ * For histogram diff, we can afford a smaller sample size and
407+ * thus a poorer estimate of the number of lines, as the hash
408+ * table (rhash) won't be filled up/grown. The number of lines
409+ * (nrecs) will be updated correctly anyway by
410+ * xdl_prepare_ctx().
411+ */
412+ sample = (XDF_DIFF_ALG (xpp -> flags ) == XDF_HISTOGRAM_DIFF
413+ ? XDL_GUESS_NLINES2 : XDL_GUESS_NLINES1 );
414+
415+ enl1 = xdl_guess_lines (mf1 , sample ) + 1 ;
416+ enl2 = xdl_guess_lines (mf2 , sample ) + 1 ;
417+
418+ if (xdl_init_classifier (& cf , enl1 + enl2 + 1 , xpp -> flags ) < 0 )
419+ return -1 ;
420+
421+ if (xdl_prepare_ctx (1 , mf1 , enl1 , xpp , & cf , & xe -> xdf1 ) < 0 ) {
422+
423+ xdl_free_classifier (& cf );
424+ return -1 ;
425+ }
426+ if (xdl_prepare_ctx (2 , mf2 , enl2 , xpp , & cf , & xe -> xdf2 ) < 0 ) {
427+
428+ xdl_free_ctx (& xe -> xdf1 );
429+ xdl_free_classifier (& cf );
430+ return -1 ;
431+ }
432+
433+ if ((XDF_DIFF_ALG (xpp -> flags ) != XDF_PATIENCE_DIFF ) &&
434+ (XDF_DIFF_ALG (xpp -> flags ) != XDF_HISTOGRAM_DIFF ) &&
435+ xdl_optimize_ctxs (& cf , & xe -> xdf1 , & xe -> xdf2 ) < 0 ) {
436+
437+ xdl_free_ctx (& xe -> xdf2 );
438+ xdl_free_ctx (& xe -> xdf1 );
439+ xdl_free_classifier (& cf );
440+ return -1 ;
441+ }
442+
443+ xdl_free_classifier (& cf );
444+
445+ return 0 ;
446+ }
0 commit comments