You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
uses the original Hash#[] definition and does not do a dynamic call to []/key?.
It's a lot more efficient to not call both of these methods.
I think this should be fixed in the semantics of pattern matching in CRuby, i.e. to not call methods dynamically as it's significantly more expensive and makes overall pattern matching slower.
(and the same thing for array pattern matching)
But I realize that's an uphill battle to change that.
Is this important in practice, does this get used in applications?
I suppose one approach here would be to check if the receiver class is Hash and in that case use HashGetOrUndefinedNode, and if it's not then use key? + [].
When using pattern matching on a
HashWithIndifferentAccess
fromActiveSupport
there appears to be a difference in behavior.Given the below example, using
ActiveSupport
7.2.1
When run on CRuby 3.3.5 it will return
true
, while on TruffleRuby24.2.0-dev-512427a6
it'll returnfalse
This appears to work on CRuby because of three things:
HashWithIndifferentAccess
extendsHash
Hash#deconstruct_keys
returnsself
.key?
followed by.[]
on the returned objectThe text was updated successfully, but these errors were encountered: