Improve the calculation of the next index for Array#__combination_next

When the index wraps around, the lower index becomes a fixed value.
This commit is contained in:
dearblue
2026-04-08 21:18:41 +09:00
parent 5d5cf0c3ea
commit 5e3e982442
+3 -7
View File
@@ -1627,13 +1627,9 @@ ary_combination_next(mrb_state *mrb, mrb_value self)
}
else {
/* Reset dependent indices */
for (mrb_int i = pos + 1; i < state->n; i++) {
if (state->permutation) {
state->indices[i] = 0;
}
else {
state->indices[i] = state->indices[i - 1];
}
mrb_int reset = state->permutation ? 0 : state->indices[pos];
for (pos++; pos < state->n; pos++) {
state->indices[pos] = reset;
}
}