mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
introduce new YARV insn newhashfromarray.
* insns.def (newhashfromarray): added to replace `core_hash_from_ary` method to eliminate method call overhead. On my environment, I got the following benchmark results: x = {x: 1} modified: 7864988.6 i/s trunk: 6004098.1 i/s - 1.31x slower x = {x: 1, y: 2} trunk: 6127338.4 i/s modified: 5232380.0 i/s - 1.17x slower x = {x: 1, y: 2, z: 3} modified: 6089553.1 i/s trunk: 5249333.5 i/s - 1.16x slower This trivial improvement should be reconsider because of usage of this instruction. * compile.c: ditto. * defs/id.def, vm.c: remove unused functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8e40a7ccb9
commit
f3c5239b16
4 changed files with 13 additions and 52 deletions
11
compile.c
11
compile.c
|
@ -3957,9 +3957,7 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node_ro
|
|||
ADD_INSN1(ret, line, duparray, ary);
|
||||
}
|
||||
else { /* COMPILE_ARRAY_TYPE_HASH */
|
||||
ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
|
||||
ADD_INSN1(ret, line, putobject, ary);
|
||||
ADD_SEND(ret, line, id_core_hash_from_ary, INT2FIX(1));
|
||||
ADD_INSN2(ret, line, newhashfromarray, INT2FIX(RARRAY_LEN(ary)/2), ary);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -3968,15 +3966,8 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node_ro
|
|||
ADD_INSN(ret, line, concatarray);
|
||||
}
|
||||
else {
|
||||
#if 0
|
||||
ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
|
||||
ADD_INSN1(ret, line, putobject, ary);
|
||||
ADD_SEND(ret, line, id_core_hash_merge_ary, INT2FIX(1));
|
||||
/* wrong number of arguments -----------------------^ */
|
||||
#else
|
||||
COMPILE_ERROR(ERROR_ARGS "core#hash_merge_ary");
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,8 +63,6 @@ firstline, predefined = __LINE__+1, %[\
|
|||
core#define_method
|
||||
core#define_singleton_method
|
||||
core#set_postexe
|
||||
core#hash_from_ary
|
||||
core#hash_merge_ary
|
||||
core#hash_merge_ptr
|
||||
core#hash_merge_kwd
|
||||
|
||||
|
|
12
insns.def
12
insns.def
|
@ -512,6 +512,18 @@ newhash
|
|||
}
|
||||
}
|
||||
|
||||
/* make new Hash object from (frozen) Array object */
|
||||
DEFINE_INSN
|
||||
newhashfromarray
|
||||
(rb_num_t num, VALUE ary)
|
||||
()
|
||||
(VALUE hash)
|
||||
{
|
||||
VM_ASSERT(num * 2 == RARRAY_LEN(ary));
|
||||
hash = rb_hash_new_with_size(num);
|
||||
rb_hash_bulk_insert(num * 2, RARRAY_CONST_PTR(ary), hash);
|
||||
}
|
||||
|
||||
/* put new Range object.(Range.new(low, high, flag)) */
|
||||
DEFINE_INSN
|
||||
newrange
|
||||
|
|
40
vm.c
40
vm.c
|
@ -2676,8 +2676,6 @@ m_core_set_postexe(VALUE self)
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE core_hash_merge_ary(VALUE hash, VALUE ary);
|
||||
static VALUE core_hash_from_ary(VALUE ary);
|
||||
static VALUE core_hash_merge_kwd(VALUE hash, VALUE kw);
|
||||
|
||||
static VALUE
|
||||
|
@ -2689,40 +2687,6 @@ core_hash_merge(VALUE hash, long argc, const VALUE *argv)
|
|||
return hash;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
m_core_hash_from_ary(VALUE self, VALUE ary)
|
||||
{
|
||||
VALUE hash;
|
||||
REWIND_CFP(hash = core_hash_from_ary(ary));
|
||||
return hash;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
core_hash_from_ary(VALUE ary)
|
||||
{
|
||||
VALUE hash = rb_hash_new_with_size(RARRAY_LEN(ary) / 2);
|
||||
|
||||
RUBY_DTRACE_CREATE_HOOK(HASH, (Check_Type(ary, T_ARRAY), RARRAY_LEN(ary)));
|
||||
return core_hash_merge_ary(hash, ary);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static VALUE
|
||||
m_core_hash_merge_ary(VALUE self, VALUE hash, VALUE ary)
|
||||
{
|
||||
REWIND_CFP(core_hash_merge_ary(hash, ary));
|
||||
return hash;
|
||||
}
|
||||
#endif
|
||||
|
||||
static VALUE
|
||||
core_hash_merge_ary(VALUE hash, VALUE ary)
|
||||
{
|
||||
Check_Type(ary, T_ARRAY);
|
||||
core_hash_merge(hash, RARRAY_LEN(ary), RARRAY_CONST_PTR(ary));
|
||||
return hash;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
m_core_hash_merge_ptr(int argc, VALUE *argv, VALUE recv)
|
||||
{
|
||||
|
@ -2864,10 +2828,6 @@ Init_VM(void)
|
|||
rb_define_method_id(klass, id_core_define_method, m_core_define_method, 2);
|
||||
rb_define_method_id(klass, id_core_define_singleton_method, m_core_define_singleton_method, 3);
|
||||
rb_define_method_id(klass, id_core_set_postexe, m_core_set_postexe, 0);
|
||||
rb_define_method_id(klass, id_core_hash_from_ary, m_core_hash_from_ary, 1);
|
||||
#if 0
|
||||
rb_define_method_id(klass, id_core_hash_merge_ary, m_core_hash_merge_ary, 2);
|
||||
#endif
|
||||
rb_define_method_id(klass, id_core_hash_merge_ptr, m_core_hash_merge_ptr, -1);
|
||||
rb_define_method_id(klass, id_core_hash_merge_kwd, m_core_hash_merge_kwd, 2);
|
||||
rb_define_method_id(klass, idProc, rb_block_proc, 0);
|
||||
|
|
Loading…
Reference in a new issue