From: Alexander Larsson Date: Wed, 19 Aug 2009 15:24:16 +0000 (+0200) Subject: Add fast path for construction with no params X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=1937765f9f9052a870cfd924b18e08aa8901a8f2;p=dana%2Fcg-glib.git Add fast path for construction with no params This avoids a bunch of code and makes construction of simple objects faster. Object construction performance improvement: Non-Threaded Threaded Simple: 14% 5% Complex: -1.1% -2.2% Other tests stable. https://bugzilla.gnome.org/show_bug.cgi?id=557100 --- diff --git a/gobject/gobject.c b/gobject/gobject.c index 175c2bf4..84324880 100644 --- a/gobject/gobject.c +++ b/gobject/gobject.c @@ -1139,7 +1139,7 @@ g_object_newv (GType object_type, guint n_parameters, GParameter *parameters) { - GObjectConstructParam *cparams, *oparams; + GObjectConstructParam *cparams = NULL, *oparams; GObjectNotifyQueue *nqueue = NULL; /* shouldn't be initialized, just to silence compiler */ GObject *object; GObjectClass *class, *unref_class = NULL; @@ -1161,6 +1161,17 @@ g_object_newv (GType object_type, n_total_cparams += 1; } + if (n_parameters == 0 && n_total_cparams == 0) + { + /* This is a simple object with no construct properties, and + * no properties are being set, so short circuit the parameter + * handling. This speeds up simple object construction. + */ + oparams = NULL; + object = class->constructor (object_type, 0, NULL); + goto did_construction; + } + /* collect parameters, sort into construction and normal ones */ oparams = g_new (GObjectConstructParam, n_parameters); cparams = g_new (GObjectConstructParam, n_total_cparams); @@ -1245,6 +1256,7 @@ g_object_newv (GType object_type, g_value_unset (cvalues + n_cvalues); g_free (cvalues); + did_construction: /* adjust freeze_count according to g_object_init() and remaining properties */ G_LOCK (construction_mutex); newly_constructed = slist_maybe_remove (&construction_objects, object);