mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-10-31 00:12:19 +01:00 
			
		
		
		
	gtype: Add check for fundamental instance type
When checking whether an instance is of a given fundamental type (such as G_TYPE_OBJECT), we can avoid over 60%+ of the cost of checking types. https://bugzilla.gnome.org/show_bug.cgi?id=730984
This commit is contained in:
		
				
					committed by
					
						 Ryan Lortie
						Ryan Lortie
					
				
			
			
				
	
			
			
			
						parent
						
							03a48e1ade
						
					
				
				
					commit
					6072e3650f
				
			| @@ -34,6 +34,7 @@ G_TYPE_CLASS_GET_PRIVATE | ||||
| G_TYPE_CHECK_INSTANCE | ||||
| G_TYPE_CHECK_INSTANCE_CAST | ||||
| G_TYPE_CHECK_INSTANCE_TYPE | ||||
| G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE | ||||
| G_TYPE_CHECK_CLASS_CAST | ||||
| G_TYPE_CHECK_CLASS_TYPE | ||||
| G_TYPE_CHECK_VALUE | ||||
| @@ -125,6 +126,7 @@ G_TYPE_FUNDAMENTAL_SHIFT | ||||
| g_type_check_instance | ||||
| g_type_check_instance_cast | ||||
| g_type_check_instance_is_a | ||||
| g_type_check_instance_is_fundamentally_a | ||||
| g_type_check_class_cast | ||||
| g_type_check_class_is_a | ||||
| g_type_check_is_value_type | ||||
|   | ||||
| @@ -3974,6 +3974,15 @@ g_type_check_instance_is_a (GTypeInstance *type_instance, | ||||
|   return check; | ||||
| } | ||||
|  | ||||
| gboolean | ||||
| g_type_check_instance_is_fundamentally_a (GTypeInstance *type_instance, | ||||
|                                           GType          fundamental_type) | ||||
| { | ||||
|   if (!type_instance || !type_instance->g_class) | ||||
|     return FALSE; | ||||
|   return NODE_FUNDAMENTAL_TYPE(lookup_type_node_I (type_instance->g_class->g_type)) == fundamental_type; | ||||
| } | ||||
|  | ||||
| gboolean | ||||
| g_type_check_class_is_a (GTypeClass *type_class, | ||||
| 			 GType       is_a_type) | ||||
|   | ||||
| @@ -489,6 +489,18 @@ struct _GTypeQuery | ||||
|  * Returns: %TRUE on success. | ||||
|  */ | ||||
| #define G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type)            (_G_TYPE_CIT ((instance), (g_type))) | ||||
| /** | ||||
|  * G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE: | ||||
|  * @instance: Location of a #GTypeInstance structure. | ||||
|  * @g_type: The fundamental type to be checked | ||||
|  * | ||||
|  * Checks if @instance is an instance of the fundamental type identified by @g_type. | ||||
|  * | ||||
|  * This macro should only be used in type implementations. | ||||
|  * | ||||
|  * Returns: %TRUE on success. | ||||
|  */ | ||||
| #define G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE(instance, g_type)            (_G_TYPE_CIFT ((instance), (g_type))) | ||||
| /** | ||||
|  * G_TYPE_INSTANCE_GET_CLASS: | ||||
|  * @instance: Location of the #GTypeInstance structure. | ||||
| @@ -1895,6 +1907,9 @@ GTypeInstance*   g_type_check_instance_cast     (GTypeInstance      *instance, | ||||
| GLIB_AVAILABLE_IN_ALL | ||||
| gboolean         g_type_check_instance_is_a	(GTypeInstance      *instance, | ||||
| 						 GType               iface_type) G_GNUC_PURE; | ||||
| GLIB_AVAILABLE_IN_2_42 | ||||
| gboolean         g_type_check_instance_is_fundamentally_a (GTypeInstance *instance, | ||||
|                                                            GType          fundamental_type) G_GNUC_PURE; | ||||
| GLIB_AVAILABLE_IN_ALL | ||||
| GTypeClass*      g_type_check_class_cast        (GTypeClass         *g_class, | ||||
| 						 GType               is_a_type); | ||||
| @@ -1934,6 +1949,7 @@ const gchar *    g_type_name_from_class         (GTypeClass	*g_class); | ||||
| #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_IGI(ip, gt, ct)         ((ct*) g_type_interface_peek (((GTypeInstance*) ip)->g_class, gt)) | ||||
| #define _G_TYPE_CIFT(ip, ft)            (g_type_check_instance_is_fundamentally_a ((GTypeInstance*) ip, ft)) | ||||
| #ifdef	__GNUC__ | ||||
| #  define _G_TYPE_CIT(ip, gt)             (G_GNUC_EXTENSION ({ \ | ||||
|   GTypeInstance *__inst = (GTypeInstance*) ip; GType __t = gt; gboolean __r; \ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user