mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-13 03:05:12 +01:00
gobject/performance: fix "type-check" test to not optimize out test code
Despite assigning the function to a variable, gcc can still detect that the function never changes and most of the test code is optimized out. Initialize it somewhere, where the compiler cannot prove that this function pointer is always set to the same value. We could also make the pointer volatile, but this approach seems preferable to me.
This commit is contained in:
parent
2cee7809d1
commit
6a231008e4
@ -712,6 +712,11 @@ test_finalization_print_result (PerformanceTest *test,
|
||||
|
||||
#define NUM_KILO_CHECKS_PER_ROUND 50
|
||||
|
||||
/* Work around g_type_check_instance_is_a being marked "pure",
|
||||
* and thus only called once for the loop. */
|
||||
static gboolean (*my_type_check_instance_is_a) (GTypeInstance *type_instance,
|
||||
GType iface_type);
|
||||
|
||||
struct TypeCheckTest {
|
||||
GObject *object;
|
||||
unsigned int n_checks;
|
||||
@ -722,6 +727,8 @@ test_type_check_setup (PerformanceTest *test)
|
||||
{
|
||||
struct TypeCheckTest *data;
|
||||
|
||||
my_type_check_instance_is_a = &g_type_check_instance_is_a;
|
||||
|
||||
data = g_new0 (struct TypeCheckTest, 1);
|
||||
data->object = g_object_new (COMPLEX_TYPE_OBJECT, NULL);
|
||||
|
||||
@ -738,12 +745,6 @@ test_type_check_init (PerformanceTest *test,
|
||||
data->n_checks = (unsigned int) (factor * NUM_KILO_CHECKS_PER_ROUND);
|
||||
}
|
||||
|
||||
|
||||
/* Work around g_type_check_instance_is_a being marked "pure",
|
||||
and thus only called once for the loop. */
|
||||
gboolean (*my_type_check_instance_is_a) (GTypeInstance *type_instance,
|
||||
GType iface_type) = &g_type_check_instance_is_a;
|
||||
|
||||
static void
|
||||
test_type_check_run (PerformanceTest *test,
|
||||
gpointer _data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user