mirror of https://github.com/GNOME/gimp.git
libgimp: Always use g_object_notify_by_pspec()
`g_object_notify()` actually takes a global lock to look up the property by its name, which means there is a performance hit (albeit tiny) every time this function is called. So let's encourage using `g_object_notify_by_pspec()` instead. Another nice advantage is that it's a bit safer at compile-time, since now typos will at least be caught by the compiler (as the enum value has to match).
This commit is contained in:
parent
9fd2433f21
commit
1f3bcb9b49
|
@ -60,7 +60,8 @@ enum
|
|||
PROP_BRUSH_NAME,
|
||||
PROP_BRUSH_OPACITY,
|
||||
PROP_BRUSH_SPACING,
|
||||
PROP_BRUSH_PAINT_MODE
|
||||
PROP_BRUSH_PAINT_MODE,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
|
||||
|
@ -142,6 +143,7 @@ static GtkWidget * gimp_brush_select_button_create_inside (GimpBrushSelectButton
|
|||
static const GtkTargetEntry target = { "application/x-gimp-brush-name", 0 };
|
||||
|
||||
static guint brush_button_signals[LAST_SIGNAL] = { 0 };
|
||||
static GParamSpec *brush_button_props[N_PROPS] = { NULL, };
|
||||
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GimpBrushSelectButton, gimp_brush_select_button,
|
||||
|
@ -169,13 +171,12 @@ gimp_brush_select_button_class_init (GimpBrushSelectButtonClass *klass)
|
|||
*
|
||||
* Since: 2.4
|
||||
*/
|
||||
g_object_class_install_property (object_class, PROP_TITLE,
|
||||
g_param_spec_string ("title",
|
||||
brush_button_props[PROP_TITLE] = g_param_spec_string ("title",
|
||||
"Title",
|
||||
"The title to be used for the brush selection popup dialog",
|
||||
_("Brush Selection"),
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
G_PARAM_CONSTRUCT_ONLY);
|
||||
|
||||
/**
|
||||
* GimpBrushSelectButton:brush-name:
|
||||
|
@ -184,12 +185,11 @@ gimp_brush_select_button_class_init (GimpBrushSelectButtonClass *klass)
|
|||
*
|
||||
* Since: 2.4
|
||||
*/
|
||||
g_object_class_install_property (object_class, PROP_BRUSH_NAME,
|
||||
g_param_spec_string ("brush-name",
|
||||
"Brush name",
|
||||
"The name of the currently selected brush",
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
brush_button_props[PROP_BRUSH_NAME] = g_param_spec_string ("brush-name",
|
||||
"Brush name",
|
||||
"The name of the currently selected brush",
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE);
|
||||
|
||||
/**
|
||||
* GimpBrushSelectButton:opacity:
|
||||
|
@ -198,12 +198,11 @@ gimp_brush_select_button_class_init (GimpBrushSelectButtonClass *klass)
|
|||
*
|
||||
* Since: 2.4
|
||||
*/
|
||||
g_object_class_install_property (object_class, PROP_BRUSH_OPACITY,
|
||||
g_param_spec_double ("brush-opacity",
|
||||
"Brush opacity",
|
||||
"The opacity of the currently selected brush",
|
||||
-1.0, 100.0, -1.0,
|
||||
GIMP_PARAM_READWRITE));
|
||||
brush_button_props[PROP_BRUSH_OPACITY] = g_param_spec_double ("brush-opacity",
|
||||
"Brush opacity",
|
||||
"The opacity of the currently selected brush",
|
||||
-1.0, 100.0, -1.0,
|
||||
GIMP_PARAM_READWRITE);
|
||||
|
||||
/**
|
||||
* GimpBrushSelectButton:spacing:
|
||||
|
@ -212,12 +211,11 @@ gimp_brush_select_button_class_init (GimpBrushSelectButtonClass *klass)
|
|||
*
|
||||
* Since: 2.4
|
||||
*/
|
||||
g_object_class_install_property (object_class, PROP_BRUSH_SPACING,
|
||||
g_param_spec_int ("brush-spacing",
|
||||
"Brush spacing",
|
||||
"The spacing of the currently selected brush",
|
||||
-G_MAXINT, 1000, -1,
|
||||
GIMP_PARAM_READWRITE));
|
||||
brush_button_props[PROP_BRUSH_SPACING] = g_param_spec_int ("brush-spacing",
|
||||
"Brush spacing",
|
||||
"The spacing of the currently selected brush",
|
||||
-G_MAXINT, 1000, -1,
|
||||
GIMP_PARAM_READWRITE);
|
||||
|
||||
/**
|
||||
* GimpBrushSelectButton:paint-mode:
|
||||
|
@ -226,13 +224,14 @@ gimp_brush_select_button_class_init (GimpBrushSelectButtonClass *klass)
|
|||
*
|
||||
* Since: 2.4
|
||||
*/
|
||||
g_object_class_install_property (object_class, PROP_BRUSH_PAINT_MODE,
|
||||
g_param_spec_int ("brush-paint-mode",
|
||||
"Brush paint mode",
|
||||
"The paint mode of the currently selected brush",
|
||||
-1, GIMP_LAYER_MODE_LUMINANCE,
|
||||
-1,
|
||||
GIMP_PARAM_READWRITE));
|
||||
brush_button_props[PROP_BRUSH_PAINT_MODE] = g_param_spec_int ("brush-paint-mode",
|
||||
"Brush paint mode",
|
||||
"The paint mode of the currently selected brush",
|
||||
-1, GIMP_LAYER_MODE_LUMINANCE,
|
||||
-1,
|
||||
GIMP_PARAM_READWRITE);
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, brush_button_props);
|
||||
|
||||
/**
|
||||
* GimpBrushSelectButton::brush-set:
|
||||
|
@ -592,7 +591,7 @@ gimp_brush_select_button_callback (const gchar *name,
|
|||
g_signal_emit (button, brush_button_signals[BRUSH_SET], 0,
|
||||
name, opacity, spacing, paint_mode, width, height, mask_data,
|
||||
dialog_closing);
|
||||
g_object_notify (G_OBJECT (button), "brush-name");
|
||||
g_object_notify_by_pspec (G_OBJECT (button), brush_button_props[PROP_BRUSH_NAME]);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -54,7 +54,8 @@ enum
|
|||
{
|
||||
PROP_0,
|
||||
PROP_TITLE,
|
||||
PROP_FONT_NAME
|
||||
PROP_FONT_NAME,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
|
||||
|
@ -102,6 +103,7 @@ static GtkWidget * gimp_font_select_button_create_inside (GimpFontSelectButton *
|
|||
static const GtkTargetEntry target = { "application/x-gimp-font-name", 0 };
|
||||
|
||||
static guint font_button_signals[LAST_SIGNAL] = { 0 };
|
||||
static GParamSpec *font_button_props[N_PROPS] = { NULL, };
|
||||
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GimpFontSelectButton, gimp_font_select_button,
|
||||
|
@ -129,13 +131,12 @@ gimp_font_select_button_class_init (GimpFontSelectButtonClass *klass)
|
|||
*
|
||||
* Since: 2.4
|
||||
*/
|
||||
g_object_class_install_property (object_class, PROP_TITLE,
|
||||
g_param_spec_string ("title",
|
||||
"Title",
|
||||
"The title to be used for the font selection popup dialog",
|
||||
_("Font Selection"),
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
font_button_props[PROP_TITLE] = g_param_spec_string ("title",
|
||||
"Title",
|
||||
"The title to be used for the font selection popup dialog",
|
||||
_("Font Selection"),
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY);
|
||||
|
||||
/**
|
||||
* GimpFontSelectButton:font-name:
|
||||
|
@ -144,12 +145,13 @@ gimp_font_select_button_class_init (GimpFontSelectButtonClass *klass)
|
|||
*
|
||||
* Since: 2.4
|
||||
*/
|
||||
g_object_class_install_property (object_class, PROP_FONT_NAME,
|
||||
g_param_spec_string ("font-name",
|
||||
"Font name",
|
||||
"The name of the currently selected font",
|
||||
"Sans-serif",
|
||||
GIMP_PARAM_READWRITE));
|
||||
font_button_props[PROP_FONT_NAME] = g_param_spec_string ("font-name",
|
||||
"Font name",
|
||||
"The name of the currently selected font",
|
||||
"Sans-serif",
|
||||
GIMP_PARAM_READWRITE);
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, font_button_props);
|
||||
|
||||
/**
|
||||
* GimpFontSelectButton::font-set:
|
||||
|
@ -352,7 +354,7 @@ gimp_font_select_button_callback (const gchar *font_name,
|
|||
|
||||
g_signal_emit (button, font_button_signals[FONT_SET], 0,
|
||||
font_name, dialog_closing);
|
||||
g_object_notify (G_OBJECT (button), "font-name");
|
||||
g_object_notify_by_pspec (G_OBJECT (button), font_button_props[PROP_FONT_NAME]);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -57,7 +57,8 @@ enum
|
|||
{
|
||||
PROP_0,
|
||||
PROP_TITLE,
|
||||
PROP_GRADIENT_NAME
|
||||
PROP_GRADIENT_NAME,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
|
||||
|
@ -119,6 +120,7 @@ static GtkWidget * gimp_gradient_select_button_create_inside (GimpGradientSelect
|
|||
static const GtkTargetEntry target = { "application/x-gimp-gradient-name", 0 };
|
||||
|
||||
static guint gradient_button_signals[LAST_SIGNAL] = { 0 };
|
||||
static GParamSpec *gradient_button_props[N_PROPS] = { NULL, };
|
||||
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GimpGradientSelectButton,
|
||||
|
@ -147,13 +149,12 @@ gimp_gradient_select_button_class_init (GimpGradientSelectButtonClass *klass)
|
|||
*
|
||||
* Since: 2.4
|
||||
*/
|
||||
g_object_class_install_property (object_class, PROP_TITLE,
|
||||
g_param_spec_string ("title",
|
||||
"Title",
|
||||
"The title to be used for the gradient selection popup dialog",
|
||||
_("Gradient Selection"),
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
gradient_button_props[PROP_TITLE] = g_param_spec_string ("title",
|
||||
"Title",
|
||||
"The title to be used for the gradient selection popup dialog",
|
||||
_("Gradient Selection"),
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY);
|
||||
|
||||
/**
|
||||
* GimpGradientSelectButton:gradient-name:
|
||||
|
@ -162,12 +163,13 @@ gimp_gradient_select_button_class_init (GimpGradientSelectButtonClass *klass)
|
|||
*
|
||||
* Since: 2.4
|
||||
*/
|
||||
g_object_class_install_property (object_class, PROP_GRADIENT_NAME,
|
||||
g_param_spec_string ("gradient-name",
|
||||
"Gradient name",
|
||||
"The name of the currently selected gradient",
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gradient_button_props[PROP_GRADIENT_NAME] = g_param_spec_string ("gradient-name",
|
||||
"Gradient name",
|
||||
"The name of the currently selected gradient",
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE);
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, gradient_button_props);
|
||||
|
||||
/**
|
||||
* GimpGradientSelectButton::gradient-set:
|
||||
|
@ -398,7 +400,7 @@ gimp_gradient_select_button_callback (const gchar *gradient_name,
|
|||
|
||||
g_signal_emit (button, gradient_button_signals[GRADIENT_SET], 0,
|
||||
gradient_name, n_samples, gradient_data, dialog_closing);
|
||||
g_object_notify (G_OBJECT (button), "gradient-name");
|
||||
g_object_notify_by_pspec (G_OBJECT (button), gradient_button_props[PROP_GRADIENT_NAME]);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -64,7 +64,8 @@ enum
|
|||
{
|
||||
PROP_0,
|
||||
PROP_TITLE,
|
||||
PROP_PALETTE_NAME
|
||||
PROP_PALETTE_NAME,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
|
||||
|
@ -101,6 +102,7 @@ static GtkWidget * gimp_palette_select_button_create_inside (GimpPaletteSelectBu
|
|||
static const GtkTargetEntry target = { "application/x-gimp-palette-name", 0 };
|
||||
|
||||
static guint palette_button_signals[LAST_SIGNAL] = { 0 };
|
||||
static GParamSpec *palette_button_props[N_PROPS] = { NULL, };
|
||||
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GimpPaletteSelectButton, gimp_palette_select_button,
|
||||
|
@ -128,13 +130,12 @@ gimp_palette_select_button_class_init (GimpPaletteSelectButtonClass *klass)
|
|||
*
|
||||
* Since: 2.4
|
||||
*/
|
||||
g_object_class_install_property (object_class, PROP_TITLE,
|
||||
g_param_spec_string ("title",
|
||||
"Title",
|
||||
"The title to be used for the palette selection popup dialog",
|
||||
_("Palette Selection"),
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
palette_button_props[PROP_TITLE] = g_param_spec_string ("title",
|
||||
"Title",
|
||||
"The title to be used for the palette selection popup dialog",
|
||||
_("Palette Selection"),
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY);
|
||||
|
||||
/**
|
||||
* GimpPaletteSelectButton:palette-name:
|
||||
|
@ -143,12 +144,13 @@ gimp_palette_select_button_class_init (GimpPaletteSelectButtonClass *klass)
|
|||
*
|
||||
* Since: 2.4
|
||||
*/
|
||||
g_object_class_install_property (object_class, PROP_PALETTE_NAME,
|
||||
g_param_spec_string ("palette-name",
|
||||
palette_button_props[PROP_PALETTE_NAME] = g_param_spec_string ("palette-name",
|
||||
"Palette name",
|
||||
"The name of the currently selected palette",
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
GIMP_PARAM_READWRITE);
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, palette_button_props);
|
||||
|
||||
/**
|
||||
* GimpPaletteSelectButton::palette-set:
|
||||
|
@ -352,7 +354,7 @@ gimp_palette_select_button_callback (const gchar *palette_name,
|
|||
|
||||
g_signal_emit (button, palette_button_signals[PALETTE_SET], 0,
|
||||
palette_name, dialog_closing);
|
||||
g_object_notify (G_OBJECT (button), "palette-name");
|
||||
g_object_notify_by_pspec (G_OBJECT (button), palette_button_props[PROP_PALETTE_NAME]);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -74,7 +74,8 @@ enum
|
|||
{
|
||||
PROP_0,
|
||||
PROP_TITLE,
|
||||
PROP_PATTERN_NAME
|
||||
PROP_PATTERN_NAME,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
|
||||
|
@ -130,6 +131,7 @@ static GtkWidget * gimp_pattern_select_button_create_inside (GimpPatternSelectBu
|
|||
static const GtkTargetEntry target = { "application/x-gimp-pattern-name", 0 };
|
||||
|
||||
static guint pattern_button_signals[LAST_SIGNAL] = { 0 };
|
||||
static GParamSpec *pattern_button_props[N_PROPS] = { NULL, };
|
||||
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GimpPatternSelectButton, gimp_pattern_select_button,
|
||||
|
@ -157,13 +159,12 @@ gimp_pattern_select_button_class_init (GimpPatternSelectButtonClass *klass)
|
|||
*
|
||||
* Since: 2.4
|
||||
*/
|
||||
g_object_class_install_property (object_class, PROP_TITLE,
|
||||
g_param_spec_string ("title",
|
||||
"Title",
|
||||
"The title to be used for the pattern selection popup dialog",
|
||||
_("Pattern Selection"),
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
pattern_button_props[PROP_TITLE] = g_param_spec_string ("title",
|
||||
"Title",
|
||||
"The title to be used for the pattern selection popup dialog",
|
||||
_("Pattern Selection"),
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY);
|
||||
|
||||
/**
|
||||
* GimpPatternSelectButton:pattern-name:
|
||||
|
@ -172,12 +173,13 @@ gimp_pattern_select_button_class_init (GimpPatternSelectButtonClass *klass)
|
|||
*
|
||||
* Since: 2.4
|
||||
*/
|
||||
g_object_class_install_property (object_class, PROP_PATTERN_NAME,
|
||||
g_param_spec_string ("pattern-name",
|
||||
"Pattern name",
|
||||
"The name of the currently selected pattern",
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
pattern_button_props[PROP_PATTERN_NAME] = g_param_spec_string ("pattern-name",
|
||||
"Pattern name",
|
||||
"The name of the currently selected pattern",
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE);
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, pattern_button_props);
|
||||
|
||||
/**
|
||||
* GimpPatternSelectButton::pattern-set:
|
||||
|
@ -426,7 +428,7 @@ gimp_pattern_select_button_callback (const gchar *pattern_name,
|
|||
|
||||
g_signal_emit (button, pattern_button_signals[PATTERN_SET], 0,
|
||||
pattern_name, width, height, bytes, dialog_closing);
|
||||
g_object_notify (G_OBJECT (button), "pattern-name");
|
||||
g_object_notify_by_pspec (G_OBJECT (button), pattern_button_props[PROP_PATTERN_NAME]);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in New Issue