diff options
author | tmm1 <tmm1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-01-10 04:54:08 +0000 |
---|---|---|
committer | tmm1 <tmm1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-01-10 04:54:08 +0000 |
commit | 58f800a278b8b70463f4afdbb23a918d8ab441ff (patch) | |
tree | d7b70525c3d84e8a4f7e3792bc06a5962481d497 /insns.def | |
parent | 9bfaeffd53d4e17b0a24281e244e2483f28f5827 (diff) |
insns.def: add opt path for Hash#[] and Hash#[]= used with str literal keys
* insns.def (opt_aref_with): new instruction to optimize Hash#[],
removing any allocation overhead when used with a string literal
key. Patch by normalperson (Eric Wong). [ruby-core:59640] [Bug #9382]
* insns.def (opt_aset_with): new instruction to optimize Hash#[]=
* compile.c (iseq_compile_each): compiler shortcuts for new
instructions
* hash.c (static VALUE rb_hash_compare_by_id_p): fix documentation for
Hash#compare_by_identity to reflect frozen string sharing
* test/ruby/test_hash.rb (class TestHash): test for new behavior
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'insns.def')
-rw-r--r-- | insns.def | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -1903,6 +1903,47 @@ opt_aset /** @c optimize + @e recv[str] = set + @j 最適化された recv[str] = set。 + */ +DEFINE_INSN +opt_aset_with +(CALL_INFO ci, VALUE key) +(VALUE recv, VALUE val) +(VALUE val) +{ + if (!SPECIAL_CONST_P(recv) && RBASIC_CLASS(recv) == rb_cHash && BASIC_OP_UNREDEFINED_P(BOP_ASET, HASH_REDEFINED_OP_FLAG)) { + rb_hash_aset(recv, key, val); + } else { + PUSH(recv); + PUSH(rb_str_resurrect(key)); + PUSH(val); + CALL_SIMPLE_METHOD(recv); + } +} + +/** + @c optimize + @e recv[str] + @j 最適化された recv[str]。 + */ +DEFINE_INSN +opt_aref_with +(CALL_INFO ci, VALUE key) +(VALUE recv) +(VALUE val) +{ + if (!SPECIAL_CONST_P(recv) && RBASIC_CLASS(recv) == rb_cHash && BASIC_OP_UNREDEFINED_P(BOP_AREF, HASH_REDEFINED_OP_FLAG)) { + val = rb_hash_aref(recv, key); + } else { + PUSH(recv); + PUSH(rb_str_resurrect(key)); + CALL_SIMPLE_METHOD(recv); + } +} + +/** + @c optimize @e optimized length @j 最適化された recv.length()。 */ |