diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-07-27 12:46:51 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-07-27 16:13:06 +0900 |
| commit | f26d00d9e81b102fababdd9c0d1b886fab30e35a (patch) | |
| tree | 057788919d060adb7d0045ef6a67cd0a7ae63d8f /mrbgems/mruby-random/src/random.c | |
| parent | 5d44f8582eb2f3011145861692d9ad42975f7a74 (diff) | |
| download | mruby-f26d00d9e81b102fababdd9c0d1b886fab30e35a.tar.gz mruby-f26d00d9e81b102fababdd9c0d1b886fab30e35a.zip | |
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.
Diffstat (limited to 'mrbgems/mruby-random/src/random.c')
| -rw-r--r-- | mrbgems/mruby-random/src/random.c | 8 |
1 files changed, 5 insertions, 3 deletions
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; } } |
