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

ruby-changes:31987

From: nobu <ko1@a...>
Date: Sun, 8 Dec 2013 15:47:45 +0900 (JST)
Subject: [ruby-changes:31987] nobu:r44066 (trunk): array.c: id_random

nobu	2013-12-08 15:47:39 +0900 (Sun, 08 Dec 2013)

  New Revision: 44066

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

  Log:
    array.c: id_random
    
    * array.c (rb_ary_shuffle_bang, rb_ary_sample): share id_random
      instead of no longer used sym_random.

  Modified files:
    trunk/array.c
Index: array.c
===================================================================
--- array.c	(revision 44065)
+++ array.c	(revision 44066)
@@ -4412,7 +4412,7 @@ rb_ary_flatten(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/array.c#L4412
 
 #define OPTHASH_GIVEN_P(opts) \
     (argc > 0 && !NIL_P((opts) = rb_check_hash_type(argv[argc-1])) && (--argc, 1))
-static VALUE sym_random;
+static ID id_random;
 
 #define RAND_UPTO(max) (long)rb_random_ulong_limited((randgen), (max)-1)
 
@@ -4431,14 +4431,12 @@ rb_ary_shuffle_bang(int argc, VALUE *arg https://github.com/ruby/ruby/blob/trunk/array.c#L4431
 {
     VALUE opts, randgen = rb_cRandom;
     long i, len;
-    static ID keyword_ids[1];
-
-    if (!keyword_ids[0]) {
-	keyword_ids[0] = rb_intern("random");
-    }
 
     if (OPTHASH_GIVEN_P(opts)) {
 	VALUE rnd;
+	ID keyword_ids[1];
+
+	keyword_ids[0] = id_random;
 	rb_get_kwargs(opts, keyword_ids, 0, 1, &rnd);
 	if (rnd != Qundef) {
 	    randgen = rnd;
@@ -4518,14 +4516,12 @@ rb_ary_sample(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/array.c#L4516
     VALUE opts, randgen = rb_cRandom;
     long n, len, i, j, k, idx[10];
     long rnds[numberof(idx)];
-    static ID keyword_ids[1];
-
-    if (!keyword_ids[0]) {
-	keyword_ids[0] = rb_intern("random");
-    }
 
     if (OPTHASH_GIVEN_P(opts)) {
 	VALUE rnd;
+	ID keyword_ids[1];
+
+	keyword_ids[0] = id_random;
 	rb_get_kwargs(opts, keyword_ids, 0, 1, &rnd);
 	if (rnd != Qundef) {
 	    randgen = rnd;
@@ -5702,7 +5698,7 @@ Init_Array(void) https://github.com/ruby/ruby/blob/trunk/array.c#L5698
     rb_define_method(rb_cArray, "bsearch", rb_ary_bsearch, 0);
 
     id_cmp = rb_intern("<=>");
-    sym_random = ID2SYM(rb_intern("random"));
+    id_random = rb_intern("random");
     id_div = rb_intern("div");
     id_power = rb_intern("**");
 }

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

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