summaryrefslogtreecommitdiff
path: root/ext/psych/lib/psych/visitors/yaml_tree.rb
diff options
context:
space:
mode:
authorAlexander Momchilov <alexandermomchilov@gmail.com>2023-12-18 04:00:48 -0500
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2023-12-19 11:07:45 +0900
commite6fa1d62faf6ba4b0f3277e2e92e6e60d4330cc8 (patch)
tree2db9e5904333c92e41349dfcf3c128e203dab0b3 /ext/psych/lib/psych/visitors/yaml_tree.rb
parent46085ef970ab50b5e1c7878345a39528823461ac (diff)
[ruby/psych] Use `compare_by_identity` instead of `object_id`
Object IDs became more expensive in Ruby 2.7. Using `Hash#compare_by_identity` let's us get the same effect, without needing to force all these objects to have object_ids assigned to them. https://github.com/ruby/psych/commit/df69e4a12e
Diffstat (limited to 'ext/psych/lib/psych/visitors/yaml_tree.rb')
-rw-r--r--ext/psych/lib/psych/visitors/yaml_tree.rb13
1 files changed, 6 insertions, 7 deletions
diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb
index 51491783c3..1dd4094c1d 100644
--- a/ext/psych/lib/psych/visitors/yaml_tree.rb
+++ b/ext/psych/lib/psych/visitors/yaml_tree.rb
@@ -15,30 +15,29 @@ module Psych
class YAMLTree < Psych::Visitors::Visitor
class Registrar # :nodoc:
def initialize
- @obj_to_id = {}
- @obj_to_node = {}
+ @obj_to_id = {}.compare_by_identity
+ @obj_to_node = {}.compare_by_identity
@targets = []
@counter = 0
end
def register target, node
- return unless target.respond_to? :object_id
@targets << target
- @obj_to_node[target.object_id] = node
+ @obj_to_node[target] = node
end
def key? target
- @obj_to_node.key? target.object_id
+ @obj_to_node.key? target
rescue NoMethodError
false
end
def id_for target
- @obj_to_id[target.object_id] ||= (@counter += 1)
+ @obj_to_id[target] ||= (@counter += 1)
end
def node_for target
- @obj_to_node[target.object_id]
+ @obj_to_node[target]
end
end