mirror of
https://github.com/ruby/ruby.git
synced 2026-10-29 00:46:26 +08:00
Add a new `Primitive.attr :always_inline`. Force inline ISEQs with this attribute. This is helpful for e.g. `BasicObject#!=`, which is otherwise megamorphic, and very small. Other JITs also have a "always inline small methods" policy but I didn't want to wade into that yet.
19 lines
652 B
Ruby
19 lines
652 B
Ruby
# ZJIT uses a Ruby definition of BasicObject#!= so it can inline the call to #==.
|
|
# Register it only for ZJIT, leaving the C definition in place otherwise.
|
|
class BasicObject
|
|
with_zjit do
|
|
if Primitive.rb_builtin_basic_definition_p(:!=)
|
|
undef :!=
|
|
|
|
def !=(other) # :nodoc:
|
|
# Keep the replacement classified as a basic method like the C definition,
|
|
# and have ZJIT inline it even when its size heuristics would say no.
|
|
Primitive.attr! :c_trace, :always_inline
|
|
|
|
# Negate truthiness without calling a possibly redefined #!.
|
|
Primitive.rb_builtin_bool_negate(self == other)
|
|
end
|
|
end
|
|
end
|
|
end
|