Re: notify freeze / thaws for GtkLabel ...



On 11 Apr 2002, Michael Meeks wrote:

> Hi there,
> 
> 	Seeing a slew of notify signalage on the nautilus profile:
> 
>    1478	GtkImage::notify
>    1717	GtkLabel::notify
>    2061	GtkAccelLabel::parent-set
>    2063	GtkAccelLabel::hierarchy-changed
>    3201	NautilusIconCanvasItem::notify
>    9750	GtkAccelLabel::notify
> 
> 	I was wondering if I could pop this patch in to at least take a factor
> of 3-4 out of that number :-) [ clearly there is prolly some issue
> causing way too many sets at my end too ].
> 
> 	May I commit ?

please, with a couple changes as suggested below.

> 
> 		Michael.
> 

> @@ -1918,6 +1922,8 @@ gtk_label_parse_uline (GtkLabel    *labe
>    g_return_val_if_fail (str != NULL, GDK_VoidSymbol);
>  
>    orig_keyval = label->mnemonic_keyval;
> +
> +  g_object_freeze_notify (G_OBJECT (label));
>    
>    gtk_label_set_label_internal (label, g_strdup (str ? str : ""));
>    gtk_label_set_use_markup_internal (label, FALSE);
> @@ -1925,6 +1931,8 @@ gtk_label_parse_uline (GtkLabel    *labe
>    
>    gtk_label_recalculate (label);
>  
> +  g_object_thaw_notify (G_OBJECT (label));
> +
>    keyval = label->mnemonic_keyval;
>    label->mnemonic_keyval = GDK_VoidSymbol;
>    

please move the thaw even _after_ label->mnemonic_keyval =...
the widget should be in a sane state when emitting notification
(things would break, e.g. if gtk_label_parse_uline() is called
again from this notification).

> @@ -1954,12 +1962,16 @@ gtk_label_set_text_with_mnemonic (GtkLab
>    g_return_if_fail (str != NULL);
>  
>    last_keyval = label->mnemonic_keyval;
> -  
> +
> +  g_object_freeze_notify (G_OBJECT (label));
> +
>    gtk_label_set_label_internal (label, g_strdup (str ? str : ""));
>    gtk_label_set_use_markup_internal (label, FALSE);
>    gtk_label_set_use_underline_internal (label, TRUE);
>    
>    gtk_label_recalculate (label);
> +
> +  g_object_thaw_notify (G_OBJECT (label));
>  
>    gtk_label_setup_mnemonic (label, last_keyval);
>  }

same here, the thawing may very well be after setting up the mnemonic.
in general, notification should only be emitted after all changes
to an object are done, so it's in a sane state when the signal
is emitted, and listeners may invoke further modifiers on the
object. as a conclusion, thawing should usually be done at the
end of a function (baring intermediate returns of course) this
also has the added benefit of multiple equal change notifications
getting coalesced.
not that the things pointed out above are your fault, the situation
currently without your changes is much worse ;)

> 
> -- 
>  mmeeks gnu org  <><, Pseudo Engineer, itinerant idiot
> 

---
ciaoTJ




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