From f26d00d9e81b102fababdd9c0d1b886fab30e35a Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 27 Jul 2017 12:46:51 +0900 Subject: Embed small size array elements in the heap. It reduces the memory consumption and sometimes improve the performance as well. For example, the consumed memory size of `bench/bm_ao_render.rb` is reduced from 1.2GB to 1GB, and its total execution time become 18.795 sec from 22.229 sec. --- mrbgems/mruby-random/src/random.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'mrbgems/mruby-random/src') diff --git a/mrbgems/mruby-random/src/random.c b/mrbgems/mruby-random/src/random.c index f81d38fe6..b865244cc 100644 --- a/mrbgems/mruby-random/src/random.c +++ b/mrbgems/mruby-random/src/random.c @@ -217,13 +217,15 @@ mrb_ary_shuffle_bang(mrb_state *mrb, mrb_value ary) for (i = RARRAY_LEN(ary) - 1; i > 0; i--) { mrb_int j; + mrb_value *ptr = RARRAY_PTR(ary); mrb_value tmp; + j = mrb_fixnum(mrb_random_mt_rand(mrb, random, mrb_fixnum_value(RARRAY_LEN(ary)))); - tmp = RARRAY_PTR(ary)[i]; - mrb_ary_ptr(ary)->ptr[i] = RARRAY_PTR(ary)[j]; - mrb_ary_ptr(ary)->ptr[j] = tmp; + tmp = ptr[i]; + ptr[i] = ptr[j]; + ptr[j] = tmp; } } -- cgit v1.2.3