summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-07 02:08:36 +0000
committerglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-07 02:08:36 +0000
commitc2f3e600d0b143fa825118dc5920e6cea8163527 (patch)
tree45d560cafb2869a421827b88a8d4bc026045378f /array.c
parentcf0838f414045a9a5c6f1d43310d332919418f89 (diff)
* 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
Diffstat (limited to 'array.c')
-rw-r--r--array.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/array.c b/array.c
index 6b2c6b2..1a71f1b 100644
--- a/array.c
+++ b/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;
}