ostruct icon indicating copy to clipboard operation
ostruct copied to clipboard

Remove `object_id` use in `OpenStruct#inspect`

Open amomchilov opened this issue 1 year ago • 0 comments
trafficstars

Found this while auditing uses of object_id in ruby/ruby. Pulled out from ruby/ruby#9276.

This PR replaces look-ups into an Array by object_ids, with an identity Set (see Set#compare_by_identity). This has the same semantics but is faster and doesn't trigger allocation of IDs for these objects.

On quirk here is that the Thread.current[:__inspect_key__] value used by OpenStruct#inspect is also shared with Set#inspect. This PR provides two implementations of #inspect, depending on whether or not the matching version of set gem is also using an identity set. See ruby/set#33.

amomchilov avatar Dec 18 '23 18:12 amomchilov