summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-random
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-07-27 12:46:51 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-07-27 16:13:06 +0900
commitf26d00d9e81b102fababdd9c0d1b886fab30e35a (patch)
tree057788919d060adb7d0045ef6a67cd0a7ae63d8f /mrbgems/mruby-random
parent5d44f8582eb2f3011145861692d9ad42975f7a74 (diff)
downloadmruby-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')
-rw-r--r--mrbgems/mruby-random/src/random.c8
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;
}
}