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
This commit is contained in:
Alexander Larsson 2009-08-19 17:24:16 +02:00
parent ffc625ec9b
commit 1937765f9f

View File

@ -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);