Re: Additions to Glib's GPtrArray API



On Thu, Feb 01, 2001 at 12:29:15AM -0500, Owen Taylor wrote:
> Eric Monsler <emonsler beamreachnetworks com> writes:
> 
>> Hi,
>> 
>> I was looking at the API for GPtrArray manipulation.
>> 
>> For my needs, I need the equivalent of the g_list_foreach()
>> functionality, like g_ptr_array_foreach(), which would be easy enough to
>> do from userland.
>> 
>> In addition, I need a function along the lines of 
>> 
>> gpointer g_ptr_array_until(GPtrArray          *array,
>>                            GPointerUserFunc   func,
>>                            gpointer           user_data);

> The question that I would ask is whether using a foreach function
> here is significiantly clearer than writing:
> 
>  for (i = 0; i < array->len; i++)
>    {
>      MyThing *thing = array->pdata[i]; // or equivalently, thing = g_ptr_array_index (array, i);
> 
>      if (thing is the right one)
>        break;
>    }
> 
> Or whatever. Certainly using a predicate function performs less well;
> One could say that you use a GArray / GPtrArray because it is directly
> indexable like a normal array.

Well the _until function isn't the same as the _foreach function.
I wouldn't have much need for the _until function, but it seems like
a _foreach could be generally useful for things like:

	g_ptr_array_foreach (strings, (GFunc)g_free, NULL);
	g_ptr_array_free (strings, TRUE);

> [ This is the problem with deciding what goes in glib - there are
> thousands and thousands of functions that make some sort of sense and
> that some people will find usefull, but if you add all of them,
> everybody will agree that the library is bloated. ]

Agreed.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]