ostruct
ostruct copied to clipboard
Remove `object_id` use in `OpenStruct#inspect`
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.