diff --git a/mrbgems/mruby-array-ext/src/array.c b/mrbgems/mruby-array-ext/src/array.c index ece9914df..97ea11e11 100644 --- a/mrbgems/mruby-array-ext/src/array.c +++ b/mrbgems/mruby-array-ext/src/array.c @@ -1619,13 +1619,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; } }