diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-04-21 04:21:14 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-04-21 04:21:14 +0000 |
commit | 36682d0e1ce3ef92ef1801e0f6a455e4ebe7ab17 (patch) | |
tree | c66b92a237f70abb15d61124f4c685848fba6f72 /insns.def | |
parent | b811b97458bd92de58d97b9ba400ae076c7c5967 (diff) | |
download | ruby-36682d0e1ce3ef92ef1801e0f6a455e4ebe7ab17.tar.gz |
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.def | 13 |
1 files changed, 5 insertions, 8 deletions
@@ -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); } |