mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-11 11:56:16 +01:00
Merge branch 'gobject-speedup1' into 'main'
Improve the GObject performance test See merge request GNOME/glib!2712
This commit is contained in:
commit
964f6ef8d0
@ -254,7 +254,7 @@ struct _ComplexObject
|
||||
{
|
||||
GObject parent_instance;
|
||||
int val1;
|
||||
int val2;
|
||||
char *val2;
|
||||
};
|
||||
|
||||
struct _ComplexObjectClass
|
||||
@ -281,9 +281,12 @@ G_DEFINE_TYPE_EXTENDED (ComplexObject, complex_object,
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_VAL1,
|
||||
PROP_VAL2
|
||||
PROP_VAL2,
|
||||
N_PROPERTIES
|
||||
};
|
||||
|
||||
static GParamSpec *pspecs[N_PROPERTIES] = { NULL, };
|
||||
|
||||
enum {
|
||||
COMPLEX_SIGNAL,
|
||||
COMPLEX_SIGNAL_EMPTY,
|
||||
@ -298,6 +301,10 @@ static guint complex_signals[COMPLEX_LAST_SIGNAL] = { 0 };
|
||||
static void
|
||||
complex_object_finalize (GObject *object)
|
||||
{
|
||||
ComplexObject *c = COMPLEX_OBJECT (object);
|
||||
|
||||
g_free (c->val2);
|
||||
|
||||
G_OBJECT_CLASS (complex_object_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
@ -315,7 +322,8 @@ complex_object_set_property (GObject *object,
|
||||
complex->val1 = g_value_get_int (value);
|
||||
break;
|
||||
case PROP_VAL2:
|
||||
complex->val2 = g_value_get_int (value);
|
||||
g_free (complex->val2);
|
||||
complex->val2 = g_value_dup_string (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
@ -337,7 +345,7 @@ complex_object_get_property (GObject *object,
|
||||
g_value_set_int (value, complex->val1);
|
||||
break;
|
||||
case PROP_VAL2:
|
||||
g_value_set_int (value, complex->val2);
|
||||
g_value_set_string (value, complex->val2);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
@ -405,26 +413,14 @@ complex_object_class_init (ComplexObjectClass *class)
|
||||
g_cclosure_marshal_VOID__UINT_POINTER,
|
||||
G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_POINTER);
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_VAL1,
|
||||
g_param_spec_int ("val1",
|
||||
"val1",
|
||||
"val1",
|
||||
0,
|
||||
G_MAXINT,
|
||||
42,
|
||||
G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_VAL2,
|
||||
g_param_spec_int ("val2",
|
||||
"val2",
|
||||
"val2",
|
||||
0,
|
||||
G_MAXINT,
|
||||
43,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
pspecs[PROP_VAL1] = g_param_spec_int ("val1", "val1", "val1",
|
||||
0, G_MAXINT, 42,
|
||||
G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
|
||||
pspecs[PROP_VAL2] = g_param_spec_string ("val2", "val2", "val2",
|
||||
NULL,
|
||||
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPERTIES, pspecs);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -445,7 +441,7 @@ complex_test_iface_init (gpointer g_iface,
|
||||
static void
|
||||
complex_object_init (ComplexObject *complex_object)
|
||||
{
|
||||
complex_object->val2 = 43;
|
||||
complex_object->val1 = 42;
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
@ -501,6 +497,69 @@ test_construction_run (PerformanceTest *test,
|
||||
objects[i] = g_object_new (type, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
test_construction_run1 (PerformanceTest *test,
|
||||
gpointer _data)
|
||||
{
|
||||
struct ConstructionTest *data = _data;
|
||||
GObject **objects = data->objects;
|
||||
int i, n_objects;
|
||||
|
||||
n_objects = data->n_objects;
|
||||
for (i = 0; i < n_objects; i++)
|
||||
objects[i] = (GObject *) g_slice_new0 (SimpleObject);
|
||||
}
|
||||
|
||||
static void
|
||||
test_complex_construction_run (PerformanceTest *test,
|
||||
gpointer _data)
|
||||
{
|
||||
struct ConstructionTest *data = _data;
|
||||
GObject **objects = data->objects;
|
||||
GType type = data->type;
|
||||
int i, n_objects;
|
||||
|
||||
n_objects = data->n_objects;
|
||||
for (i = 0; i < n_objects; i++)
|
||||
objects[i] = g_object_new (type, "val1", 5, "val2", "thousand", NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
test_complex_construction_run1 (PerformanceTest *test,
|
||||
gpointer _data)
|
||||
{
|
||||
struct ConstructionTest *data = _data;
|
||||
GObject **objects = data->objects;
|
||||
GType type = data->type;
|
||||
int i, n_objects;
|
||||
|
||||
n_objects = data->n_objects;
|
||||
for (i = 0; i < n_objects; i++)
|
||||
{
|
||||
ComplexObject *object;
|
||||
object = (ComplexObject *)g_object_new (type, NULL);
|
||||
object->val1 = 5;
|
||||
object->val2 = g_strdup ("thousand");
|
||||
objects[i] = (GObject *)object;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_complex_construction_run2 (PerformanceTest *test,
|
||||
gpointer _data)
|
||||
{
|
||||
struct ConstructionTest *data = _data;
|
||||
GObject **objects = data->objects;
|
||||
GType type = data->type;
|
||||
int i, n_objects;
|
||||
|
||||
n_objects = data->n_objects;
|
||||
for (i = 0; i < n_objects; i++)
|
||||
{
|
||||
objects[i] = g_object_new (type, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_construction_finish (PerformanceTest *test,
|
||||
gpointer _data)
|
||||
@ -512,6 +571,17 @@ test_construction_finish (PerformanceTest *test,
|
||||
g_object_unref (data->objects[i]);
|
||||
}
|
||||
|
||||
static void
|
||||
test_construction_finish1 (PerformanceTest *test,
|
||||
gpointer _data)
|
||||
{
|
||||
struct ConstructionTest *data = _data;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < data->n_objects; i++)
|
||||
g_slice_free (SimpleObject, (SimpleObject *)data->objects[i]);
|
||||
}
|
||||
|
||||
static void
|
||||
test_construction_teardown (PerformanceTest *test,
|
||||
gpointer _data)
|
||||
@ -933,12 +1003,42 @@ static PerformanceTest tests[] = {
|
||||
test_construction_teardown,
|
||||
test_construction_print_result
|
||||
},
|
||||
{
|
||||
"simple-construction1",
|
||||
simple_object_get_type,
|
||||
test_construction_setup,
|
||||
test_construction_init,
|
||||
test_construction_run1,
|
||||
test_construction_finish1,
|
||||
test_construction_teardown,
|
||||
test_construction_print_result
|
||||
},
|
||||
{
|
||||
"complex-construction",
|
||||
complex_object_get_type,
|
||||
test_construction_setup,
|
||||
test_construction_init,
|
||||
test_construction_run,
|
||||
test_complex_construction_run,
|
||||
test_construction_finish,
|
||||
test_construction_teardown,
|
||||
test_construction_print_result
|
||||
},
|
||||
{
|
||||
"complex-construction1",
|
||||
complex_object_get_type,
|
||||
test_construction_setup,
|
||||
test_construction_init,
|
||||
test_complex_construction_run1,
|
||||
test_construction_finish,
|
||||
test_construction_teardown,
|
||||
test_construction_print_result
|
||||
},
|
||||
{
|
||||
"complex-construction2",
|
||||
complex_object_get_type,
|
||||
test_construction_setup,
|
||||
test_construction_init,
|
||||
test_complex_construction_run2,
|
||||
test_construction_finish,
|
||||
test_construction_teardown,
|
||||
test_construction_print_result
|
||||
|
Loading…
Reference in New Issue
Block a user