diff options
author | Étienne Barrié <[email protected]> | 2024-07-29 12:15:02 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2024-09-05 12:46:02 +0200 |
commit | a99707cd9c6a1d53cf8ebc883dc210219bd67a28 (patch) | |
tree | f435c276f693070ff3102ded5ed2cea3adcc1493 /vm_insnhelper.c | |
parent | 63cbe3f6ac9feb44a2e43b1f853e2ca7e049316c (diff) |
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 <[email protected]>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11406
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r-- | vm_insnhelper.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 227bfa2004..bc133f4013 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -6110,6 +6110,17 @@ vm_objtostring(const rb_iseq_t *iseq, VALUE recv, CALL_DATA cd) } static VALUE +vm_opt_ary_freeze(VALUE ary, int bop, ID id) +{ + if (BASIC_OP_UNREDEFINED_P(bop, ARRAY_REDEFINED_OP_FLAG)) { + return ary; + } + else { + return Qundef; + } +} + +static VALUE vm_opt_str_freeze(VALUE str, int bop, ID id) { if (BASIC_OP_UNREDEFINED_P(bop, STRING_REDEFINED_OP_FLAG)) { |