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,43 +227,46 @@ 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 */
if (vars->y > 0) {
row = q->pixels + (vars->y - 1) * q->w;
next_vars = flood_fill_call_next(q, row,
from, to,
func, user_data,
vars, -1);
if (next_vars != NULL) {
goto call;
} }
}
if (vars->y < q->h - 1) { /* Seed new flood-fills */
row = q->pixels + (vars->y + 1) * q->w; if (vars->y > 0) {
row = q->pixels + (vars->y - 1) * q->w;
next_vars = flood_fill_call_next(q, row, next_vars = flood_fill_call_next(q, row,
from, to, from, to,
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->y < q->h - 1) {
/* Restore the previous context */ row = q->pixels + (vars->y + 1) * q->w;
next_vars = vars - 1;
goto return_from_call; next_vars = flood_fill_call_next(q, row,
from, to,
func, user_data,
vars, 1);
if (next_vars != NULL) {
continue;
}
}
if (vars > stack) {
/* Restore the previous context */
next_vars = vars - 1;
continue;
}
break;
} }
} }