gobject optimization



I recently looked at some profiles, showing g_type_check_instance_cast
in a prominent position. Instrumenting it showed that on testgtk --bench
ALL, 1031830 of 3661172 calls or 28.18% are checking an object against
its own type. Consequently, doing the same optimization that was done on
g_type_check_instance_is_a() and g_type_check_class_is_a() back in July
2001 should have some effect. 

Here is a patch.

Matthias

PS The number of calls to g_type_check_class_cast() is much smaller
(55681/211885), thus I'm not sure it deserves the same treatment.


Index: gobject/gtype.h
===================================================================
RCS file: /cvs/gnome/glib/gobject/gtype.h,v
retrieving revision 1.46
diff -u -b -B -p -r1.46 gtype.h
--- gobject/gtype.h	15 Oct 2002 21:16:18 -0000	1.46
+++ gobject/gtype.h	19 Nov 2002 01:04:46 -0000
@@ -340,8 +340,19 @@ G_CONST_RETURN gchar* g_type_name_from_c
 
 /* --- implementation bits --- */
 #ifndef G_DISABLE_CAST_CHECKS
+#ifdef	__GNUC__
+#  define _G_TYPE_CIC(ip, gt, ct)             (G_GNUC_EXTENSION ({ \
+  GTypeInstance *__inst = (GTypeInstance*) ip; GType __t = gt; ct *__r; \
+  if (__inst && __inst->g_class && __inst->g_class->g_type == __t) \
+    __r = (ct*) __inst; \
+  else \
+    __r = (ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt); \
+  __r; \
+}))
+#else  /* !__GNUC__ */
 #  define _G_TYPE_CIC(ip, gt, ct) \
     ((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt))
+#endif
 #  define _G_TYPE_CCC(cp, gt, ct) \
     ((ct*) g_type_check_class_cast ((GTypeClass*) cp, gt))
 #else /* G_DISABLE_CAST_CHECKS */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]