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