Re: Removing GBSearchArray from libgtk



On 30 Aug 2001, Owen Taylor wrote:

> Here is a patch to remove the usages of GBSearchArray from GTK+.
> 
>  * GBSearchArray is replaced with GArray + bsearch
> 
>  * I've simplified the code as well by combining various cut-and-paste
>     and near-cut-and-paste sections.
> 
>  * It's a slight deoptimization in some places because bsearch()
>    doesn't provide for lookups for insertion, so I just did them
>    linearly but unless people start settting a _lot_ of RC properties
>    in their RC styles, this shouldn't be a problem.
>    
>    If it turns out to be one from profiling, then it will be
>    easy to fix ... and there are better algorithms for merging
>    two sorted data sets than a insertion sort, even with
>    bsearch lookups. :-)
> 
> I would consider the new code considerably easier to understand,
> though that's mostly because of the general simplification,
> 
> Regards,
>                                         Owen   
> 
> (P.S. - if you start fixing up the private version of GBSearchArray,
> I'd suggest making _insert() return a gboolean "did-it-insert" 
> value ... a lot of the confusing bits of the original code
> are ad-hoc ways to figure out if insertion really happened or not.)
> 

ok, except for a few formatting things, e.g.:


> +    style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
> +
> +  i = 0;
> +  while (i < style->rc_properties->len)
> +    {
> +      gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
> +      if (cmp == 0)
> +	
> +	{

here,

> +	  if (replace)
> +	    {

the code looks correct to me, though quite a bit more
inefficient, but we can still fix that.
for now, it'd be good to get this into CVS so we can move
bsearcharray in glib, thanks for cooking up the converion
to garray.

---
ciaoTJ






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