* array.c (rb_ary_shuffle_bang): use RARRAY_PTR_USE() without WB

because there are not new relations.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43563 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
glass 2013-11-07 02:08:36 +00:00
Родитель cf0838f414
Коммит c2f3e600d0
2 изменённых файлов: 19 добавлений и 15 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Thu Nov 7 11:06:05 2013 Masaki Matsushita <glass.saga@gmail.com>
* array.c (rb_ary_shuffle_bang): use RARRAY_PTR_USE() without WB
because there are not new relations.
Thu Nov 7 10:34:12 2013 Masaki Matsushita <glass.saga@gmail.com>
* array.c (rb_ary_sample): use rb_ary_dup().

29
array.c
Просмотреть файл

@ -4443,28 +4443,27 @@ static VALUE sym_random;
static VALUE
rb_ary_shuffle_bang(int argc, VALUE *argv, VALUE ary)
{
VALUE *ptr, opts, *snap_ptr, randgen = rb_cRandom;
long i, snap_len;
VALUE opts, randgen = rb_cRandom;
long i, len;
if (OPTHASH_GIVEN_P(opts)) {
randgen = rb_hash_lookup2(opts, sym_random, randgen);
}
rb_check_arity(argc, 0, 0);
rb_ary_modify(ary);
i = RARRAY_LEN(ary);
ptr = RARRAY_PTR(ary);
snap_len = i;
snap_ptr = ptr;
while (i) {
long j = RAND_UPTO(i);
VALUE tmp;
if (snap_len != RARRAY_LEN(ary) || snap_ptr != RARRAY_PTR(ary)) {
rb_raise(rb_eRuntimeError, "modified during shuffle");
i = len = RARRAY_LEN(ary);
RARRAY_PTR_USE(ary, ptr, {
while (i) {
long j = RAND_UPTO(i);
VALUE tmp;
if (len != RARRAY_LEN(ary) || ptr != RARRAY_CONST_PTR(ary)) {
rb_raise(rb_eRuntimeError, "modified during shuffle");
}
tmp = ptr[--i];
ptr[i] = ptr[j];
ptr[j] = tmp;
}
tmp = ptr[--i];
ptr[i] = ptr[j];
ptr[j] = tmp;
}
}); /* WB: no new reference */
return ary;
}