mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Optimized instruction for Hash#freeze
If a Hash which is empty or only using literals is frozen, we detect this as a peephole optimization and change the instructions to be `opt_hash_freeze`. [Feature #20684] Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
This commit is contained in:
parent
a99707cd9c
commit
bf9879791a
Notes:
git
2024-09-05 10:46:23 +00:00
10 changed files with 325 additions and 158 deletions
15
insns.def
15
insns.def
|
@ -934,6 +934,21 @@ opt_ary_freeze
|
|||
}
|
||||
}
|
||||
|
||||
DEFINE_INSN
|
||||
opt_hash_freeze
|
||||
(VALUE hash, CALL_DATA cd)
|
||||
()
|
||||
(VALUE val)
|
||||
{
|
||||
val = vm_opt_hash_freeze(hash, BOP_FREEZE, idFreeze);
|
||||
|
||||
if (UNDEF_P(val)) {
|
||||
RUBY_DTRACE_CREATE_HOOK(HASH, RHASH_SIZE(hash) << 1);
|
||||
PUSH(rb_hash_resurrect(hash));
|
||||
CALL_SIMPLE_METHOD();
|
||||
}
|
||||
}
|
||||
|
||||
DEFINE_INSN
|
||||
opt_str_freeze
|
||||
(VALUE str, CALL_DATA cd)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue