summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-08 06:47:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-08 06:47:39 +0000
commit1018f57f2c98f589b8dd2f176793df0081bb52a4 (patch)
tree0224ad4669c5ba6d33323c24692a8b3ba9a4d281 /array.c
parent7f5a9f3881acd46f5b96419776eb713c42963af7 (diff)
array.c: id_random
* array.c (rb_ary_shuffle_bang, rb_ary_sample): share id_random instead of no longer used sym_random. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44066 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/array.c b/array.c
index 9a93d7f..e6a45e8 100644
--- a/array.c
+++ b/array.c
@@ -4412,7 +4412,7 @@ rb_ary_flatten(int argc, VALUE *argv, VALUE ary)
#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 *argv, VALUE ary)
{
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, VALUE ary)
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)
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("**");
}