From 17c8c9aed4ba4360f5afd31cfa12f36be225db0b Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Wed, 24 Apr 2024 21:02:34 -0400 Subject: [PATCH] Replace qsort with `std::sort` --- sc2/src/uqm/planets/pstarmap-modern.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/sc2/src/uqm/planets/pstarmap-modern.cpp b/sc2/src/uqm/planets/pstarmap-modern.cpp index 56519cb86..8aaf55093 100644 --- a/sc2/src/uqm/planets/pstarmap-modern.cpp +++ b/sc2/src/uqm/planets/pstarmap-modern.cpp @@ -21,6 +21,8 @@ #include #include +#include +#include #include "../gamestr.h" #include "../starmap.h" @@ -29,40 +31,33 @@ #include "../sis.h" #include "../sounds.h" -static int -compStarName (const void *ptr1, const void *ptr2) +static bool +compStarName (const int index1, const int index2) { - int index1; - int index2; - - index1 = *(const int *) ptr1; - index2 = *(const int *) ptr2; if (star_array[index1].Postfix != star_array[index2].Postfix) { return utf8StringCompare (GAME_STRING (star_array[index1].Postfix), - GAME_STRING (star_array[index2].Postfix)); + GAME_STRING (star_array[index2].Postfix)) < 0; } if (star_array[index1].Prefix < star_array[index2].Prefix) - return -1; - - if (star_array[index1].Prefix > star_array[index2].Prefix) - return 1; + return true; - return 0; + return false; } static void SortStarsOnName (STAR_SEARCH_STATE *pSS) { + std::cerr << "ADAM C++: Star sorting!" << std::endl; int i; int *sorted = pSS->SortedStars; for (i = 0; i < GetStarCount(); i++) sorted[i] = i; - std::qsort (sorted, GetStarCount(), sizeof (int), compStarName); + std::sort( sorted, sorted + GetStarCount(), compStarName ); }