From: Yu Watanabe Date: Sat, 12 Apr 2025 03:10:32 +0000 (+0900) Subject: libudev-list: use hashmap_dump_sorted() X-Git-Tag: v258-rc1~792^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e8a4defa8ea0f4657b0e8a7fccce6c12d996ed5;p=thirdparty%2Fsystemd.git libudev-list: use hashmap_dump_sorted() --- diff --git a/src/libudev/libudev-list.c b/src/libudev/libudev-list.c index 12d86210922..a3e972b0ed5 100644 --- a/src/libudev/libudev-list.c +++ b/src/libudev/libudev-list.c @@ -4,7 +4,6 @@ #include "hashmap.h" #include "libudev-list-internal.h" #include "list.h" -#include "sort-util.h" /** * SECTION:libudev-list @@ -136,10 +135,6 @@ struct udev_list *udev_list_free(struct udev_list *list) { return mfree(list); } -static int udev_list_entry_compare_func(struct udev_list_entry * const *a, struct udev_list_entry * const *b) { - return strcmp((*a)->name, (*b)->name); -} - struct udev_list_entry *udev_list_get_entry(struct udev_list *list) { if (!list) return NULL; @@ -156,18 +151,10 @@ struct udev_list_entry *udev_list_get_entry(struct udev_list *list) { LIST_PREPEND(entries, list->entries, hashmap_first(list->unique_entries)); else { _cleanup_free_ struct udev_list_entry **buf = NULL; - struct udev_list_entry *entry, **p; - buf = new(struct udev_list_entry *, n); - if (!buf) + if (hashmap_dump_sorted(list->unique_entries, (void***) &buf, /* ret_n = */ NULL) < 0) return NULL; - p = buf; - HASHMAP_FOREACH(entry, list->unique_entries) - *p++ = entry; - - typesafe_qsort(buf, n, udev_list_entry_compare_func); - for (size_t j = n; j > 0; j--) LIST_PREPEND(entries, list->entries, buf[j-1]); }