summaryrefslogtreecommitdiff
path: root/insns.def
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-21 04:21:14 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-21 04:21:14 +0000
commit4ee09d914db903cb6f4cf50c4bb03c163694b465 (patch)
treec66b92a237f70abb15d61124f4c685848fba6f72 /insns.def
parentbdc6d41640f07d260b66eaaeea38145789227513 (diff)
refactor hash literal
Same as rb_ary_tmp_new_from_values(), it reduces vm_exec_core binary size from 26,176 bytes to 26,080 bytes. But this time, also with a bit of optimizations: - Because we are allocating a new hash and no back references are introduced at all, we can safely skip write barriers. - Also, the iteration never recurs. We can avoid complicated function callbacks by using st_insert instead of st_update. ---- * hash.c (rb_hash_new_from_values): refactor extract the bulk insert into a function. * hash.c (rb_hash_new_from_object): also refactor. * hash.c (rb_hash_s_create): use the new functions. * insns.def (newhash): ditto. * vm.c (core_hash_from_ary): ditto. * iternal.h: export the new function. ----------------------------------------------------------- benchmark results: minimum results in each 7 measurements. Execution time (sec) name before after loop_whileloop2 0.135 0.134 vm2_bighash* 1.236 0.687 Speedup ratio: compare with the result of `before' (greater is better) name after loop_whileloop2 1.008 vm2_bighash* 1.798 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58427 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'insns.def')
-rw-r--r--insns.def13
1 files changed, 5 insertions, 8 deletions
diff --git a/insns.def b/insns.def
index a056b221d5..36ba48eaea 100644
--- a/insns.def
+++ b/insns.def
@@ -492,16 +492,13 @@ newhash
(...)
(VALUE val) // inc += 1 - num;
{
- rb_num_t i;
-
RUBY_DTRACE_CREATE_HOOK(HASH, num);
- val = rb_hash_new();
-
- for (i = num; i > 0; i -= 2) {
- const VALUE v = TOPN(i - 2);
- const VALUE k = TOPN(i - 1);
- rb_hash_aset(val, k, v);
+ if (num) {
+ val = rb_hash_new_from_values(num, STACK_ADDR_FROM_TOP(num));
+ }
+ else {
+ val = rb_hash_new();
}
POPN(num);
}