-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove object_id
use in OpenStruct#inspect
#58
base: master
Are you sure you want to change the base?
Conversation
# Returns a string containing a detailed summary of the keys and values. | ||
# | ||
def inspect | ||
ids = (Thread.current[InspectKey] ||= Set.new.compare_by_identity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using an identity Set here matches what pp
does:
https://github.com/ruby/ruby/blob/e8064c6c2c317be78953b4d19226368580af0dca/lib/pp.rb#L146-L161
@@ -380,27 +380,59 @@ def delete_field(name, &block) | |||
end | |||
end | |||
|
|||
def self.__inspect_supports_identity_set? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is checked by the corresponding PR in set
:
f6003a8
to
6becba8
Compare
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 byOpenStruct#inspect
is also shared withSet#inspect
. This PR provides two implementations of#inspect
, depending on whether or not the matching version ofset
gem is also using an identity set. See ruby/set#33.