[glib/gobject-speedups: 23/23] Avoid g_type_class_peek
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/gobject-speedups: 23/23] Avoid g_type_class_peek
- Date: Fri, 20 May 2022 13:44:26 +0000 (UTC)
commit 21fd63221a81170b7a0c6db1d327588b1496aaac
Author: Matthias Clasen <mclasen redhat com>
Date: Thu May 19 21:53:31 2022 -0400
Avoid g_type_class_peek
Most of the time, properties belong to the class
we set them on. Check that first, before going
into GType, which takes locks and whatnot.
gobject/gobject.c | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index 90c68a31ca..18a2fb96c3 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -1579,18 +1579,19 @@ object_get_property (GObject *object,
GParamSpec *pspec,
GValue *value)
{
- GObjectClass *class = g_type_class_peek (pspec->owner_type);
+ GTypeInstance *inst = (GTypeInstance *) object;
+ GObjectClass *class;
guint param_id = PARAM_SPEC_PARAM_ID (pspec);
- if (class == NULL)
- {
- g_warning ("'%s::%s' is not a valid property name; '%s' is not a GObject subtype",
- g_type_name (pspec->owner_type), pspec->name, g_type_name (pspec->owner_type));
- return;
- }
+ if (G_LIKELY (inst->g_class->g_type == pspec->owner_type))
+ class = (GObjectClass *) inst->g_class;
+ else
+ class = g_type_class_peek (pspec->owner_type);
+
+ g_assert (class != NULL);
if (G_IS_PARAM_SPEC_OVERRIDE (pspec))
- pspec = ((GParamSpecOverride *)pspec)->overridden;
+ pspec = ((GParamSpecOverride *) pspec)->overridden;
consider_issuing_property_deprecation_warning (pspec);
@@ -1603,16 +1604,17 @@ object_set_property (GObject *object,
const GValue *value,
GObjectNotifyQueue *nqueue)
{
- GObjectClass *class = g_type_class_peek (pspec->owner_type);
+ GTypeInstance *inst = (GTypeInstance *) object;
+ GObjectClass *class;
GParamSpecClass *pclass;
guint param_id = PARAM_SPEC_PARAM_ID (pspec);
- if (G_UNLIKELY (class == NULL))
- {
- g_warning ("'%s::%s' is not a valid property name; '%s' is not a GObject subtype",
- g_type_name (pspec->owner_type), pspec->name, g_type_name (pspec->owner_type));
- return;
- }
+ if (G_LIKELY (inst->g_class->g_type == pspec->owner_type))
+ class = (GObjectClass *) inst->g_class;
+ else
+ class = g_type_class_peek (pspec->owner_type);
+
+ g_assert (class != NULL);
if (G_IS_PARAM_SPEC_OVERRIDE (pspec))
pspec = ((GParamSpecOverride *)pspec)->overridden;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]