[前][次][番号順一覧][スレッド一覧]

ruby-changes:31484

From: glass <ko1@a...>
Date: Thu, 7 Nov 2013 11:08:42 +0900 (JST)
Subject: [ruby-changes:31484] glass:r43563 (trunk): * array.c (rb_ary_shuffle_bang): use RARRAY_PTR_USE() without WB

glass	2013-11-07 11:08:36 +0900 (Thu, 07 Nov 2013)

  New Revision: 43563

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43563

  Log:
    * array.c (rb_ary_shuffle_bang): use RARRAY_PTR_USE() without WB
      because there are not new relations.

  Modified files:
    trunk/ChangeLog
    trunk/array.c
Index: array.c
===================================================================
--- array.c	(revision 43562)
+++ array.c	(revision 43563)
@@ -4443,28 +4443,27 @@ static VALUE sym_random; https://github.com/ruby/ruby/blob/trunk/array.c#L4443
 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;
 }
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43562)
+++ ChangeLog	(revision 43563)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Nov  7 11:06:05 2013  Masaki Matsushita  <glass.saga@g...>
+
+	* 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@g...>
 
 	* array.c (rb_ary_sample): use rb_ary_dup().

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]