diff options
author | Marcus Meissner <marcus@jet.franken.de> | 2012-05-11 16:40:52 +0000 |
---|---|---|
committer | Marcus Meissner <marcus@jet.franken.de> | 2012-05-11 16:40:52 +0000 |
commit | edfb26fbce8f2b0ab980a4afcba72b50e5ee6f78 (patch) | |
tree | 7c5780c3f3eddd5daf20ec883951c2c6150deb55 /libgphoto2 | |
parent | fe8a604c981c0fe9ec726f52d76ea3636d176883 (diff) | |
download | libgphoto2-edfb26fbce8f2b0ab980a4afcba72b50e5ee6f78.tar.gz |
use qsort() instead of bubble sort for gp_list_sort
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@14019 67ed7778-7388-44ab-90cf-0a291f65f57c
Diffstat (limited to 'libgphoto2')
-rw-r--r-- | libgphoto2/gphoto2-list.c | 36 |
1 files changed, 10 insertions, 26 deletions
diff --git a/libgphoto2/gphoto2-list.c b/libgphoto2/gphoto2-list.c index e852226a6..9bf1c103a 100644 --- a/libgphoto2/gphoto2-list.c +++ b/libgphoto2/gphoto2-list.c @@ -226,43 +226,27 @@ gp_list_append (CameraList *list, const char *name, const char *value) } /** - * \internal - */ -static void -exchange (CameraList *list, int x, int y) -{ - char *tmp; - - tmp = list->entry[x].name; - list->entry[x].name = list->entry[y].name; - list->entry[y].name = tmp; - - tmp = list->entry[x].value; - list->entry[x].value = list->entry[y].value; - list->entry[y].value = tmp; -} - -/** * Sorts the \c list entries with respect to the names. * * \param list a #CameraList * \return a gphoto2 error code * **/ +static int +cmp_list (const void *a, const void *b) { + const struct _entry *ca = a; + const struct _entry *cb = b; + + return strcmp (ca->name, cb->name); +} + int gp_list_sort (CameraList *list) { - int x, y, z; CHECK_LIST (list); - for (x = 0; x < list->used - 1; x++) - for (y = x + 1; y < list->used; y++) { - z = strcmp (list->entry[x].name, list->entry[y].name); - if (z > 0) - exchange (list, x, y); - } - - return (GP_OK); + qsort (list->entry, list->used, sizeof(list->entry[0]), cmp_list); + return GP_OK; } /** |