flood_fill_seed: Switch from goto to while

This commit is contained in:
YAMAMOTO Takashi 2021-05-11 14:48:55 +09:00
parent a436fde8a0
commit 87ca2b6c2d

View file

@ -16,6 +16,7 @@
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
#include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include "quirc_internal.h" #include "quirc_internal.h"
@ -213,9 +214,7 @@ static void flood_fill_seed(struct quirc *q,
QUIRC_ASSERT(from != to); QUIRC_ASSERT(from != to);
QUIRC_ASSERT(q->pixels[y0 * q->w + x0] == from); QUIRC_ASSERT(q->pixels[y0 * q->w + x0] == from);
struct quirc_flood_fill_vars *vars;
struct quirc_flood_fill_vars *next_vars; struct quirc_flood_fill_vars *next_vars;
quirc_pixel_t *row;
/* Set up the first context */ /* Set up the first context */
next_vars = stack; next_vars = stack;
@ -228,12 +227,12 @@ static void flood_fill_seed(struct quirc *q,
&next_vars->left_up, &next_vars->right); &next_vars->left_up, &next_vars->right);
next_vars->left_down = next_vars->left_up; next_vars->left_down = next_vars->left_up;
call: while (true) {
return_from_call: struct quirc_flood_fill_vars * const vars = next_vars;
vars = next_vars; quirc_pixel_t *row;
if (vars == last_vars) { if (vars == last_vars) {
return; break;
} }
/* Seed new flood-fills */ /* Seed new flood-fills */
@ -245,7 +244,7 @@ return_from_call:
func, user_data, func, user_data,
vars, -1); vars, -1);
if (next_vars != NULL) { if (next_vars != NULL) {
goto call; continue;
} }
} }
@ -257,14 +256,17 @@ return_from_call:
func, user_data, func, user_data,
vars, 1); vars, 1);
if (next_vars != NULL) { if (next_vars != NULL) {
goto call; continue;
} }
} }
if (vars > stack) { if (vars > stack) {
/* Restore the previous context */ /* Restore the previous context */
next_vars = vars - 1; next_vars = vars - 1;
goto return_from_call; continue;
}
break;
} }
} }