qom: introduce object_class_get_list_sorted

Unify half a dozen copies of very similar code (the only difference being
whether comparisons were case-sensitive) and use it also in Tricore,
which did not do any sorting of CPU model names.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2018-03-03 08:33:10 +01:00
parent 819fd4699c
commit 47c66009ab
8 changed files with 30 additions and 65 deletions

View file

@ -891,6 +891,19 @@ GSList *object_class_get_list(const char *implements_type,
return list;
}
static gint object_class_cmp(gconstpointer a, gconstpointer b)
{
return strcasecmp(object_class_get_name((ObjectClass *)a),
object_class_get_name((ObjectClass *)b));
}
GSList *object_class_get_list_sorted(const char *implements_type,
bool include_abstract)
{
return g_slist_sort(object_class_get_list(implements_type, include_abstract),
object_class_cmp);
}
void object_ref(Object *obj)
{
if (!obj) {