mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-20 23:51:29 -07:00
Consolidate duplicate implementations of compare_integers
Both Inertia and Twiddle previously included static implementations of this exact same function, which was passed to `qsort()` as a comparator. With this change, a single global implementation is provided in misc.c, which will hopefully reduce code duplication going forward. I'm refactoring this in preparation for the upcoming fallback polygon fill function, which I'm about to add.
This commit is contained in:

committed by
Simon Tatham

parent
1c1899ee1c
commit
2a57df6be9
14
twiddle.c
14
twiddle.c
@ -532,18 +532,6 @@ static void free_game(game_state *state)
|
||||
sfree(state);
|
||||
}
|
||||
|
||||
static int compare_int(const void *av, const void *bv)
|
||||
{
|
||||
const int *a = (const int *)av;
|
||||
const int *b = (const int *)bv;
|
||||
if (*a < *b)
|
||||
return -1;
|
||||
else if (*a > *b)
|
||||
return +1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *solve_game(const game_state *state, const game_state *currstate,
|
||||
const char *aux, const char **error)
|
||||
{
|
||||
@ -758,7 +746,7 @@ static game_state *execute_move(const game_state *from, const char *move)
|
||||
* conveniently being able to get hold of a clean state from
|
||||
* which to practise manoeuvres.
|
||||
*/
|
||||
qsort(ret->grid, ret->w*ret->h, sizeof(int), compare_int);
|
||||
qsort(ret->grid, ret->w*ret->h, sizeof(int), compare_integers);
|
||||
for (i = 0; i < ret->w*ret->h; i++)
|
||||
ret->grid[i] &= ~3;
|
||||
ret->used_solve = true;
|
||||
|
Reference in New Issue
Block a user