From 5e3e9824428ec486db9d216848f3ff73777d9645 Mon Sep 17 00:00:00 2001 From: dearblue Date: Wed, 8 Apr 2026 21:18:41 +0900 Subject: [PATCH] Improve the calculation of the next index for `Array#__combination_next` When the index wraps around, the lower index becomes a fixed value. --- mrbgems/mruby-array-ext/src/array.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/mrbgems/mruby-array-ext/src/array.c b/mrbgems/mruby-array-ext/src/array.c index 70473c087..68383c2e5 100644 --- a/mrbgems/mruby-array-ext/src/array.c +++ b/mrbgems/mruby-array-ext/src/array.c @@ -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; } }