Optimize instructions when creating an array just to call include? (#12123)

* Add opt_duparray_send insn to skip the allocation on `#include?`

If the method isn't going to modify the array we don't need to copy it.
This avoids the allocation / array copy for things like `[:a, :b].include?(x)`.

This adds a BOP for include? and tracks redefinition for it on Array.

Co-authored-by: Andrew Novoselac <andrew.novoselac@shopify.com>

* YJIT: Implement opt_duparray_send include_p

Co-authored-by: Andrew Novoselac <andrew.novoselac@shopify.com>

* Update opt_newarray_send to support simple forms of include?(arg)

Similar to opt_duparray_send but for non-static arrays.

* YJIT: Implement opt_newarray_send include_p

---------

Co-authored-by: Andrew Novoselac <andrew.novoselac@shopify.com>
This commit is contained in:
Randy Stauner 2024-11-26 12:31:08 -07:00 committed by GitHub
parent c1dcd1d496
commit 1dd40ec18a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
Notes: git 2024-11-26 19:31:33 +00:00
Merged-By: maximecb <maximecb@ruby-lang.org>
14 changed files with 573 additions and 156 deletions

1
vm.c
View file

@ -2263,6 +2263,7 @@ vm_init_redefined_flag(void)
OP(NilP, NIL_P), (C(NilClass));
OP(Cmp, CMP), (C(Integer), C(Float), C(String));
OP(Default, DEFAULT), (C(Hash));
OP(IncludeP, INCLUDE_P), (C(Array));
#undef C
#undef OP
}