qom/object: initialize type_table in static ctor with fundamental QOM types
This saves us having to check if it's initialized everytime we have to access it. No other QOM type should be initialized or accessed during static ctor calls, so we don't depend on their ordering. Suggested-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Link: https://lore.kernel.org/qemu-devel/20260514172303.1484273-3-pierrick.bouvier@oss.qualcomm.com Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Pierrick Bouvier committed
May 14, 2026 at 10:23 UTC
05ad8be329fc054f48d277dedb53ffa185980224
1 file changed
+5
-13
qom/object.c
+5
-13
@@ -76,28 +76,19 @@ struct TypeImpl
76
77
static Type type_interface;
78
79
-static GHashTable *type_table_get(void)
80
-{
81
- static GHashTable *type_table;
82
-
83
- if (type_table == NULL) {
84
- type_table = g_hash_table_new(g_str_hash, g_str_equal);
85
- }
86
-
87
- return type_table;
88
-}
79
+static GHashTable *type_table;
80
81
static bool enumerating_types;
82
83
static void type_table_add(TypeImpl *ti)
84
{
85
assert(!enumerating_types);
95
- g_hash_table_insert(type_table_get(), (void *)ti->name, ti);
86
+ g_hash_table_insert(type_table, (void *)ti->name, ti);
87
}
88
89
static TypeImpl *type_table_lookup(const char *name)
90
{
100
- return g_hash_table_lookup(type_table_get(), name);
91
+ return g_hash_table_lookup(type_table, name);
92
}
93
94
static TypeImpl *type_new(const TypeInfo *info)
@@ -1069,7 +1060,7 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
1060
OCFData data = { fn, implements_type, include_abstract, opaque };
1061
1062
enumerating_types = true;
1072
- g_hash_table_foreach(type_table_get(), object_class_foreach_tramp, &data);
1063
+ g_hash_table_foreach(type_table, object_class_foreach_tramp, &data);
1064
enumerating_types = false;
1065
}
1066
@@ -2859,6 +2850,7 @@ static void __attribute__((constructor)) register_types(void)
2850
.abstract = true,
2851
};
2852
2853
+ type_table = g_hash_table_new(g_str_hash, g_str_equal);
2854
type_interface = type_register_internal(&interface_info);
2855
type_register_internal(&object_info);
2856
}