@@ -134,99 +134,81 @@ static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t
134134}
135135
136136
137+ static void xdl_free_ctx (xdfile_t * xdf )
138+ {
139+ xdl_free (xdf -> rhash );
140+ xdl_free (xdf -> rindex );
141+ xdl_free (xdf -> rchg - 1 );
142+ xdl_free (xdf -> ha );
143+ xdl_free (xdf -> recs );
144+ xdl_cha_free (& xdf -> rcha );
145+ }
146+
147+
137148static int xdl_prepare_ctx (unsigned int pass , mmfile_t * mf , long narec , xpparam_t const * xpp ,
138149 xdlclassifier_t * cf , xdfile_t * xdf ) {
139- unsigned int hbits ;
140- long nrec , hsize , bsize ;
150+ long bsize ;
141151 unsigned long hav ;
142152 char const * blk , * cur , * top , * prev ;
143153 xrecord_t * crec ;
144- xrecord_t * * recs ;
145- xrecord_t * * rhash ;
146- unsigned long * ha ;
147- char * rchg ;
148- long * rindex ;
149154
150- ha = NULL ;
151- rindex = NULL ;
152- rchg = NULL ;
153- rhash = NULL ;
154- recs = NULL ;
155+ xdf -> ha = NULL ;
156+ xdf -> rindex = NULL ;
157+ xdf -> rchg = NULL ;
158+ xdf -> rhash = NULL ;
159+ xdf -> recs = NULL ;
155160
156161 if (xdl_cha_init (& xdf -> rcha , sizeof (xrecord_t ), narec / 4 + 1 ) < 0 )
157162 goto abort ;
158- if (!XDL_ALLOC_ARRAY (recs , narec ))
163+ if (!XDL_ALLOC_ARRAY (xdf -> recs , narec ))
159164 goto abort ;
160165
161- hbits = xdl_hashbits ((unsigned int ) narec );
162- hsize = 1 << hbits ;
163- if (!XDL_CALLOC_ARRAY (rhash , hsize ))
166+ xdf -> hbits = xdl_hashbits ((unsigned int ) narec );
167+ if (!XDL_CALLOC_ARRAY (xdf -> rhash , 1 << xdf -> hbits ))
164168 goto abort ;
165169
166- nrec = 0 ;
170+ xdf -> nrec = 0 ;
167171 if ((cur = blk = xdl_mmfile_first (mf , & bsize ))) {
168172 for (top = blk + bsize ; cur < top ; ) {
169173 prev = cur ;
170174 hav = xdl_hash_record (& cur , top , xpp -> flags );
171- if (XDL_ALLOC_GROW (recs , nrec + 1 , narec ))
175+ if (XDL_ALLOC_GROW (xdf -> recs , xdf -> nrec + 1 , narec ))
172176 goto abort ;
173177 if (!(crec = xdl_cha_alloc (& xdf -> rcha )))
174178 goto abort ;
175179 crec -> ptr = prev ;
176180 crec -> size = (long ) (cur - prev );
177181 crec -> ha = hav ;
178- recs [nrec ++ ] = crec ;
179- if (xdl_classify_record (pass , cf , rhash , hbits , crec ) < 0 )
182+ xdf -> recs [xdf -> nrec ++ ] = crec ;
183+ if (xdl_classify_record (pass , cf , xdf -> rhash , xdf -> hbits , crec ) < 0 )
180184 goto abort ;
181185 }
182186 }
183187
184- if (!XDL_CALLOC_ARRAY (rchg , nrec + 2 ))
188+ if (!XDL_CALLOC_ARRAY (xdf -> rchg , xdf -> nrec + 2 ))
185189 goto abort ;
186190
187191 if ((XDF_DIFF_ALG (xpp -> flags ) != XDF_PATIENCE_DIFF ) &&
188192 (XDF_DIFF_ALG (xpp -> flags ) != XDF_HISTOGRAM_DIFF )) {
189- if (!XDL_ALLOC_ARRAY (rindex , nrec + 1 ))
193+ if (!XDL_ALLOC_ARRAY (xdf -> rindex , xdf -> nrec + 1 ))
190194 goto abort ;
191- if (!XDL_ALLOC_ARRAY (ha , nrec + 1 ))
195+ if (!XDL_ALLOC_ARRAY (xdf -> ha , xdf -> nrec + 1 ))
192196 goto abort ;
193197 }
194198
195- xdf -> nrec = nrec ;
196- xdf -> recs = recs ;
197- xdf -> hbits = hbits ;
198- xdf -> rhash = rhash ;
199- xdf -> rchg = rchg + 1 ;
200- xdf -> rindex = rindex ;
199+ xdf -> rchg += 1 ;
201200 xdf -> nreff = 0 ;
202- xdf -> ha = ha ;
203201 xdf -> dstart = 0 ;
204- xdf -> dend = nrec - 1 ;
202+ xdf -> dend = xdf -> nrec - 1 ;
205203
206204 return 0 ;
207205
208206abort :
209- xdl_free (ha );
210- xdl_free (rindex );
211- xdl_free (rchg );
212- xdl_free (rhash );
213- xdl_free (recs );
214- xdl_cha_free (& xdf -> rcha );
207+ xdl_free_ctx (xdf );
215208 return -1 ;
216209}
217210
218211
219- static void xdl_free_ctx (xdfile_t * xdf ) {
220-
221- xdl_free (xdf -> rhash );
222- xdl_free (xdf -> rindex );
223- xdl_free (xdf -> rchg - 1 );
224- xdl_free (xdf -> ha );
225- xdl_free (xdf -> recs );
226- xdl_cha_free (& xdf -> rcha );
227- }
228-
229-
230212void xdl_free_env (xdfenv_t * xe ) {
231213
232214 xdl_free_ctx (& xe -> xdf2 );
0 commit comments