[Bug #21106] Remove the useless last iteration

When only one element remains, this simply swaps the first identical
element and has no actual effect.
This commit is contained in:
Nobuyoshi Nakada 2025-02-02 19:34:52 +09:00
parent ace39a3ed4
commit 8dd0d63550
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465
Notes: git 2025-02-02 16:19:09 +00:00

View File

@ -6701,7 +6701,7 @@ rb_ary_shuffle_bang(rb_execution_context_t *ec, VALUE ary, VALUE randgen)
rb_ary_modify(ary);
i = len = RARRAY_LEN(ary);
RARRAY_PTR_USE(ary, ptr, {
while (i) {
while (i > 1) {
long j = RAND_UPTO(i);
VALUE tmp;
if (len != RARRAY_LEN(ary) || ptr != RARRAY_CONST_PTR(ary)) {