if __GNUC__ is defined, inline a test for an exact type match for

Wed Jul 18 19:42:31 2001  Tim Janik  <timj@gtk.org>

        * gtype.h: if __GNUC__ is defined, inline a test for an exact type
        match for instances and classes in G_TYPE_CHECK_INSTANCE_TYPE() and
        G_TYPE_CHECK_CLASS_TYPE() before calling g_type_instance_is_a().
This commit is contained in:
Tim Janik 2001-08-15 09:19:52 +00:00 committed by Tim Janik
parent 3171bd213c
commit a80fc07f32
3 changed files with 36 additions and 9 deletions

View File

@ -1,3 +1,9 @@
Wed Jul 18 19:42:31 2001 Tim Janik <timj@gtk.org>
* gtype.h: if __GNUC__ is defined, inline a test for an exact type
match for instances and classes in G_TYPE_CHECK_INSTANCE_TYPE() and
G_TYPE_CHECK_CLASS_TYPE() before calling g_type_instance_is_a().
Sun Aug 12 02:07:10 2001 Tim Janik <timj@gtk.org> Sun Aug 12 02:07:10 2001 Tim Janik <timj@gtk.org>
* gvaluearray.[hc]: fix preallocation logic, support DISABLE_MEM_POOLS * gvaluearray.[hc]: fix preallocation logic, support DISABLE_MEM_POOLS

View File

@ -451,7 +451,7 @@ type_lookup_iface_entry_L (TypeNode *node,
} }
static inline gboolean static inline gboolean
type_lookup_prerequisite (TypeNode *iface, type_lookup_prerequisite_L (TypeNode *iface,
GType prerequisite_type) GType prerequisite_type)
{ {
if (NODE_IS_IFACE (iface) && IFACE_NODE_N_PREREQUISITES (iface)) if (NODE_IS_IFACE (iface) && IFACE_NODE_N_PREREQUISITES (iface))
@ -817,13 +817,14 @@ check_add_interface_L (GType instance_type,
tnode = lookup_type_node_L (NODE_PARENT_TYPE (iface)); tnode = lookup_type_node_L (NODE_PARENT_TYPE (iface));
if (NODE_PARENT_TYPE (tnode) && !type_lookup_iface_entry_L (node, tnode)) if (NODE_PARENT_TYPE (tnode) && !type_lookup_iface_entry_L (node, tnode))
{ {
/* 2001/7/31:timj: erk, i guess this warning is junk as interface derivation is flat */
g_warning ("cannot add sub-interface `%s' to type `%s' which does not conform to super-interface `%s'", g_warning ("cannot add sub-interface `%s' to type `%s' which does not conform to super-interface `%s'",
NODE_NAME (iface), NODE_NAME (iface),
NODE_NAME (node), NODE_NAME (node),
NODE_NAME (tnode)); NODE_NAME (tnode));
return FALSE; return FALSE;
} }
tnode = find_conforming_type_L (node, iface); tnode = find_conforming_type_L (node, iface); // FIXME: iface overriding
if (tnode) if (tnode)
{ {
g_warning ("cannot add interface type `%s' to type `%s', since type `%s' already conforms to interface", g_warning ("cannot add interface type `%s' to type `%s', since type `%s' already conforms to interface",
@ -1167,6 +1168,7 @@ g_type_interface_add_prerequisite (GType interface_type,
{ {
guint i; guint i;
/* can have at most one publically installable instantiatable prerequisite */
for (i = 0; i < IFACE_NODE_N_PREREQUISITES (iface); i++) for (i = 0; i < IFACE_NODE_N_PREREQUISITES (iface); i++)
{ {
TypeNode *prnode = lookup_type_node_L (IFACE_NODE_PREREQUISITES (iface)[i]); TypeNode *prnode = lookup_type_node_L (IFACE_NODE_PREREQUISITES (iface)[i]);
@ -1197,7 +1199,7 @@ g_type_interface_add_prerequisite (GType interface_type,
type_iface_add_prerequisite_W (iface, prerequisite_node); type_iface_add_prerequisite_W (iface, prerequisite_node);
} }
else else
g_warning ("prerequisite `%s' for interface `%s' is not instantiatable or interface", g_warning ("prerequisite `%s' for interface `%s' is neither instantiatable nor interface",
type_descriptive_name_L (prerequisite_type), type_descriptive_name_L (prerequisite_type),
type_descriptive_name_L (interface_type)); type_descriptive_name_L (interface_type));
G_WRITE_UNLOCK (&type_rw_lock); G_WRITE_UNLOCK (&type_rw_lock);
@ -2132,7 +2134,7 @@ type_node_is_a_L (TypeNode *node,
return TRUE; return TRUE;
else if (support_prerequisites && else if (support_prerequisites &&
NODE_IS_IFACE (node) && NODE_IS_IFACE (node) &&
type_lookup_prerequisite (node, NODE_TYPE (iface_node))) type_lookup_prerequisite_L (node, NODE_TYPE (iface_node)))
return TRUE; return TRUE;
else else
return FALSE; return FALSE;
@ -2704,7 +2706,7 @@ g_type_value_table_peek (GType type)
node = lookup_type_node_L (type); node = lookup_type_node_L (type);
if (!node) if (!node)
{ {
g_warning ("type id `%u' is invalid", type); g_warning (G_STRLOC ": type id `%u' is invalid", type);
G_READ_UNLOCK (&type_rw_lock); G_READ_UNLOCK (&type_rw_lock);
return NULL; return NULL;
} }

View File

@ -367,12 +367,31 @@ G_CONST_RETURN gchar* g_type_name_from_class (GTypeClass *g_class);
# define _G_TYPE_CCC(cp, gt, ct) ((ct*) cp) # define _G_TYPE_CCC(cp, gt, ct) ((ct*) cp)
#endif /* G_DISABLE_CAST_CHECKS */ #endif /* G_DISABLE_CAST_CHECKS */
#define _G_TYPE_CHI(ip) (g_type_check_instance ((GTypeInstance*) ip)) #define _G_TYPE_CHI(ip) (g_type_check_instance ((GTypeInstance*) ip))
#define _G_TYPE_CIT(ip, gt) (g_type_instance_is_a ((GTypeInstance*) ip, gt))
#define _G_TYPE_CCT(cp, gt) (g_type_class_is_a ((GTypeClass*) cp, gt))
#define _G_TYPE_CVH(vl, gt) (g_type_check_value_holds ((GValue*) vl, gt)) #define _G_TYPE_CVH(vl, gt) (g_type_check_value_holds ((GValue*) vl, gt))
#define _G_TYPE_CHV(vl) (g_type_check_value ((GValue*) vl)) #define _G_TYPE_CHV(vl) (g_type_check_value ((GValue*) vl))
#define _G_TYPE_IGC(ip, gt, ct) ((ct*) (((GTypeInstance*) ip)->g_class)) #define _G_TYPE_IGC(ip, gt, ct) ((ct*) (((GTypeInstance*) ip)->g_class))
#define _G_TYPE_IGI(ip, gt, ct) ((ct*) g_type_interface_peek (((GTypeInstance*) ip)->g_class, gt)) #define _G_TYPE_IGI(ip, gt, ct) ((ct*) g_type_interface_peek (((GTypeInstance*) ip)->g_class, gt))
#ifdef __GNUC__
# define _G_TYPE_CIT(ip, gt) ({ \
GTypeInstance *__inst = (GTypeInstance*) ip; GType __t = gt; gboolean __r; \
if (__inst && __inst->g_class && __inst->g_class->g_type == __t) \
__r = TRUE; \
else \
__r = g_type_instance_is_a (__inst, __t); \
__r; \
})
# define _G_TYPE_CCT(cp, gt) ({ \
GTypeClass *__class = (GTypeClass*) cp; GType __t = gt; gboolean __r; \
if (__class && __class->g_type == __t) \
__r = TRUE; \
else \
__r = g_type_class_is_a (__class, __t); \
__r; \
})
#else /* !__GNUC__ */
# define _G_TYPE_CIT(ip, gt) (g_type_instance_is_a ((GTypeInstance*) ip, gt))
# define _G_TYPE_CCT(cp, gt) (g_type_class_is_a ((GTypeClass*) cp, gt))
#endif /* !__GNUC__ */
#define G_TYPE_FLAG_RESERVED_ID_BIT (1 << 30) #define G_TYPE_FLAG_RESERVED_ID_BIT (1 << 30)
extern GTypeDebugFlags _g_type_debug_flags; extern GTypeDebugFlags _g_type_debug_flags;