@@ -173,68 +173,19 @@ static tagEntry *copyTag (tagEntry *o)
173173	return  n ;
174174}
175175
176- struct  tagEntryHolder  {
177- 	tagEntry  * e ;
178- };
179- struct  tagEntryArray  {
180- 	int  count ;
181- 	int  length ;
182- 	struct  tagEntryHolder  * a ;
183- };
184- 
185- static  struct  tagEntryArray  * tagEntryArrayNew  (void )
186- {
187- 	struct  tagEntryArray  *  a  =  eMalloc  (sizeof  (struct  tagEntryArray ));
188- 
189- 	a -> count  =  0 ;
190- 	a -> length  =  1024 ;
191- 	a -> a  =  eMalloc (a -> length  *  sizeof  (a -> a [0 ]));
192- 
193- 	return  a ;
194- }
195- 
196- static  void  tagEntryArrayPush  (struct  tagEntryArray  * a , tagEntry  * e )
197- {
198- 	if  (a -> count  +  1  ==  a -> length )
199- 	{
200- 		if  (a -> length  *  2  <  a -> length ) {
201- 			fprintf (stderr , "too large array allocation" );
202- 			exit (1 );
203- 		}
204- 
205- 		struct  tagEntryHolder  * tmp  =  eRealloc  (a -> a , sizeof  (a -> a [0 ]) *  (a -> length  *  2 ));
206- 		a -> a  =  tmp ;
207- 		a -> length  *= 2 ;
208- 	}
209- 
210- 	a -> a [a -> count ++ ].e  =  e ;
211- }
212- 
213- static  void  tagEntryArrayFree  (struct  tagEntryArray  * a , int  freeTags )
214- {
215- 	if  (freeTags )
216- 	{
217- 		for  (int  i  =  0 ; i  <  a -> count ; i ++ )
218- 			freeCopiedTag  (a -> a [i ].e );
219- 	}
220- 	free  (a -> a );
221- 	free  (a );
222- }
223- 
224176static  int  compareTagEntry  (const  void  * a , const  void  * b )
225177{
226- 	return  s_compare  ((( struct   tagEntryHolder   * ) a ) -> e , (( struct   tagEntryHolder   * ) b ) -> e , Sorter );
178+ 	return  s_compare  (a ,  b , Sorter );
227179}
228180
229181static  void  walkTags  (tagFile  * const  file , tagEntry  * first_entry ,
230182					  tagResult  (*  nextfn ) (tagFile  * const , tagEntry  * ),
231183					  void  (*  actionfn ) (const  tagEntry  * , void  * ), void  * data ,
232184					  struct  actionSpec  * actionSpec )
233185{
234- 	struct  tagEntryArray  * a  =  NULL ;
235- 
186+ 	ptrArray  * a  =  NULL ;
236187	if  (Sorter )
237- 		a  =  tagEntryArrayNew  ( );
188+ 		a  =  ptrArrayNew  (( ptrArrayDeleteFunc ) freeCopiedTag );
238189
239190	do 
240191	{
@@ -265,7 +216,7 @@ static void walkTags (tagFile *const file, tagEntry *first_entry,
265216		if  (a )
266217		{
267218			tagEntry  * e  =  copyTag  (shadow );
268- 			tagEntryArrayPush  (a , e );
219+ 			ptrArrayAdd  (a , e );
269220		}
270221		else 
271222			(*  actionfn ) (shadow , data );
@@ -282,10 +233,14 @@ static void walkTags (tagFile *const file, tagEntry *first_entry,
282233
283234	if  (a )
284235	{
285- 		qsort  (a -> a , a -> count , sizeof  (a -> a [0 ]), compareTagEntry );
286- 		for  (int  i  =  0 ; i  <  a -> count ; i ++ )
287- 			(*  actionfn ) (a -> a [i ].e , data );
288- 		tagEntryArrayFree  (a , 1 );
236+ 		ptrArraySort  (a , compareTagEntry );
237+ 		size_t  count  =  ptrArrayCount (a );
238+ 		for  (unsigned int   i  =  0 ; i  <  count ; i ++ )
239+ 		{
240+ 			tagEntry  * e  =  ptrArrayItem  (a , i );
241+ 			(*  actionfn ) (e , data );
242+ 		}
243+ 		ptrArrayDelete  (a );
289244	}
290245}
291246#else 
0 commit comments