gvalues
- From: suk <suk artax karlin mff cuni cz>
- To: gtk-devel-list gnome org
- Subject: gvalues
- Date: Thu, 24 Apr 2003 18:34:15 +0200
I'm writing about minor performance disadvantage when accesing
style_property values. So it goes:
This code pattern is at several places. Example from GtkButon.c
static const GtkBorder default_default_outside_border = { 0, 0, 0, 0 };
static const GtkBorder default_default_border = { 1, 1, 1, 1 };
.....
static void gtk_button_get_props (GtkButton *button,
GtkBorder *default_border,
GtkBorder *default_outside_border,
gboolean *interior_focus)
{
GtkWidget *widget = GTK_WIDGET (button);
GtkBorder *tmp_border;
if (default_border)
{
gtk_widget_style_get (widget, "default_border", &tmp_border,NULL);
if (tmp_border)
{
*default_border = *tmp_border;
g_free (tmp_border);
}
else
*default_border = default_default_border;
}
....
This function is called from other code like this:
GtkBorder default_border;
gtk_button_get_props (button, &default_border, NULL, NULL);
This tries to get_style_property and if not found then return some
fallback value. But it unreasonably allocates/frees memory and copies
the value twice (branch when property exists) and once otherwise.
This of course goes against the idea in gtk_style_... to have access
to values fast.
Variant 1:
So maybe it would be better to have
boolean gtk_widget_style_get_property (widget, "default_border", &variable );
instead of
void gtk_widget_style_get_property (widget, "default_border", &variable );
With this we can make it with only one copying (in each branch one).
if (!gtk_widget_style_get (widget, "default_border", default_border, NULL))
*default_border = default_default_border;
So one copying is done inside gtk_widget_style_get
- but this time, without alocating new struct.
and if there is no such property, we do copying outside.
I don't understand G_VALUES properly, but this would be fairly easy for
someone who does.
Variant 2:
Of course we can make no copying at all. Because
void* gtk_widget_style_get_property (widget, "default_border" );
gets the value from style->property_cache, so if we promise to not touch
and not store for a long time.... This variant will not get through, i'm
sure.
Suk
--
signed short (mail)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]