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
Found this while auditing uses of
object_id
inruby/ruby
. Pulled out from ruby/ruby#9276.This PR replaces look-ups into an Array by
object_id
s, with an identity Set (seeSet#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 bySet#inspect
is also shared withOpenStruct#inspect
. This PR provides two implementations of#inspect
, depending on whether or not the matching version of theostruct
gem is also using an identity set. See ruby/ostruct#58