ref: f21c7d27664bc43d3e5a9401756860c03055c3aa
parent: 11a8149d673d96bec17d6487b5fa95b5bf5ffd6b
author: Simon Tatham <anakin@pobox.com>
date: Thu Apr 20 09:56:44 EDT 2023
Consistently use snew_dsf to allocate dsfs. All remaining cases where a dsf was allocated via snewn(foo, int) are removed by this change.
--- a/bridges.c
+++ b/bridges.c
@@ -1771,7 +1771,7 @@
ret->solver = snew(struct solver_state);
ret->solver->dsf = snew_dsf(wh);
- ret->solver->tmpdsf = snewn(wh, int);
+ ret->solver->tmpdsf = snew_dsf(wh);
ret->solver->refcount = 1;
--- a/filling.c
+++ b/filling.c
@@ -407,7 +407,7 @@
* contains a shuffled list of numbers {0, ..., sz-1}. */
for (i = 0; i < sz; ++i) board[i] = i;
- dsf = snewn(sz, int);
+ dsf = snew_dsf(sz);
retry:
dsf_init(dsf, sz);
shuffle(board, sz, sizeof (int), rs);
--- a/galaxies.c
+++ b/galaxies.c
@@ -3959,7 +3959,7 @@
/*
* Get the completion information.
*/
- dsf = snewn(w * h, int);
+ dsf = snew_dsf(w * h);
colours = snewn(w * h, int);
check_complete(state, dsf, colours);
--- a/loopy.c
+++ b/loopy.c
@@ -455,7 +455,7 @@
ret->solver_status = sstate->solver_status;
ret->diff = sstate->diff;
- ret->dotdsf = snewn(num_dots, int);
+ ret->dotdsf = snew_dsf(num_dots);
ret->looplen = snewn(num_dots, int);
dsf_copy(ret->dotdsf, sstate->dotdsf, num_dots);
memcpy(ret->looplen, sstate->looplen,
@@ -485,7 +485,7 @@
}
if (sstate->linedsf) {
- ret->linedsf = snewn(num_edges, int);
+ ret->linedsf = snew_dsf(num_edges);
dsf_copy(ret->linedsf, sstate->linedsf, num_edges);
} else {
ret->linedsf = NULL;
--- a/pearl.c
+++ b/pearl.c
@@ -349,7 +349,7 @@
* We maintain a dsf of connected squares, together with a
* count of the size of each equivalence class.
*/
- dsf = snewn(w*h, int);
+ dsf = snew_dsf(w*h);
dsfsize = snewn(w*h, int);
/*
--- a/singles.c
+++ b/singles.c
@@ -498,7 +498,7 @@
static bool check_complete(game_state *state, unsigned flags)
{
- int *dsf = snewn(state->n, int);
+ int *dsf = snew_dsf(state->n);
int x, y, i, error = 0, nwhite, w = state->w, h = state->h;
if (flags & CC_MARK_ERRORS) {
--- a/slant.c
+++ b/slant.c
@@ -312,10 +312,10 @@
{
int W = w+1, H = h+1;
struct solver_scratch *ret = snew(struct solver_scratch);
- ret->connected = snewn(W*H, int);
+ ret->connected = snew_dsf(W*H);
ret->exits = snewn(W*H, int);
ret->border = snewn(W*H, bool);
- ret->equiv = snewn(w*h, int);
+ ret->equiv = snew_dsf(w*h);
ret->slashval = snewn(w*h, signed char);
ret->vbitmap = snewn(w*h, unsigned char);
return ret;
--- a/tracks.c
+++ b/tracks.c
@@ -1373,8 +1373,7 @@
/* TODO eventually we should pull this out into a solver struct and keep it
updated as we connect squares. For now we recreate it every time we try
this particular solver step. */
- dsf = snewn(w*h, int);
- dsf_init(dsf, w*h);
+ dsf = snew_dsf(w*h);
/* Work out the connectedness of the current loop set. */
for (x = 0; x < w; x++) {
@@ -1878,8 +1877,7 @@
}
}
- dsf = snewn(w*h, int);
- dsf_init(dsf, w*h);
+ dsf = snew_dsf(w*h);
for (x = 0; x < w; x++) {
for (y = 0; y < h; y++) {