string.c (mrb_memsearch_qs): reduce the scope of local variables

This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-01-10 16:21:39 +09:00
parent 31f2d93657
commit c2f148e15d
+3 -1
View File
@@ -477,15 +477,17 @@ mrb_memsearch_qs(const unsigned char *xs, mrb_int m, const unsigned char *ys, mr
return -1;
}
else {
const unsigned char *x = xs, *xe = xs + m;
const unsigned char *y = ys;
ptrdiff_t qstable[256];
/* Preprocessing */
for (int i = 0; i < 256; i++)
qstable[i] = m + 1;
const unsigned char *x = xs, *xe = xs + m;
for (; x < xe; x++)
qstable[*x] = xe - x;
/* Searching */
for (; y + m <= ys + n; y += *(qstable + y[m])) {
if (*xs == *y && memcmp(xs, y, m) == 0)