gobject: inline G_TYPE_IS() macros within gtype.c

If you take a release build (--buildtype=release) previously of GLib,
functions such as g_type_create_instance() would call out to
g_type_test_flags() which you can see by disassembling and looking for the
call instruction to <g_type_test_flags> via the library ABI.

Now that the previous commit allows checking abstract and deprecated flags
it makes sense to let the compiler optimize those checks into a single
pass. This is only possible if the functions themselves are inlined.

Additionally, any time we have the same TypeNode we would want to be able
to reuse that node rather than re-locate it.
This commit is contained in:
Christian Hergert 2023-09-26 15:13:09 -07:00 committed by Philip Withnall
parent 5de7dd5a4b
commit ab2fe494a4

View File

@ -155,6 +155,9 @@
#define g_assert_type_system_initialized() \
g_assert (static_quark_type_flags)
/* Make sure G_TYPE_IS_*() macros still end up inlined */
#define g_type_test_flags(t,f) _g_type_test_flags(t,f)
#define TYPE_FUNDAMENTAL_FLAG_MASK (G_TYPE_FLAG_CLASSED | \
G_TYPE_FLAG_INSTANTIATABLE | \
G_TYPE_FLAG_DERIVABLE | \
@ -200,6 +203,8 @@ typedef struct _IFaceHolder IFaceHolder;
/* --- prototypes --- */
static inline gboolean _g_type_test_flags (GType type,
guint flags);
static inline GTypeFundamentalInfo* type_node_fundamental_info_I (TypeNode *node);
static void type_add_flags_W (TypeNode *node,
GTypeFlags flags);
@ -4005,9 +4010,9 @@ g_type_get_instance_count (GType type)
}
/* --- implementation details --- */
gboolean
g_type_test_flags (GType type,
guint flags)
static inline gboolean
_g_type_test_flags (GType type,
guint flags)
{
TypeNode *node;
gboolean result = FALSE;
@ -4062,6 +4067,13 @@ g_type_test_flags (GType type,
return result;
}
gboolean
(g_type_test_flags) (GType type,
guint flags)
{
return _g_type_test_flags (type, flags);
}
/**
* g_type_get_plugin:
* @type: #GType to retrieve the plugin for