From 47c66009ab793241e8210b3018c77a9ce9506aa8 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Sat, 3 Mar 2018 08:33:10 +0100 Subject: qom: introduce object_class_get_list_sorted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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é Signed-off-by: Paolo Bonzini --- qom/object.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'qom/object.c') diff --git a/qom/object.c b/qom/object.c index 755ad03..6088f55 100644 --- a/qom/object.c +++ b/qom/object.c @@ -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) { -- cgit v1.1