ruby / set

This library provides the Set class, which deals with a collection of unordered values with no duplicates.
BSD 2-Clause "Simplified" License
23 stars 13 forks source link

Remove `object_id` use in `Set#inspect` #33

Open amomchilov opened 10 months ago

amomchilov commented 10 months ago

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 Set#inspect is also shared with OpenStruct#inspect. This PR provides two implementations of #inspect, depending on whether or not the matching version of the ostruct gem is also using an identity set. See ruby/ostruct#58