Skip to content

Commit 58223f0

Browse files
committed
Cache access to Psych.load_tags in Visitor::ToRuby
1 parent 0abce07 commit 58223f0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/psych/visitors/to_ruby.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def initialize ss, class_loader, symbolize_names: false, freeze: false
2424
super()
2525
@st = {}
2626
@ss = ss
27+
@load_tags = Psych.load_tags
2728
@domain_types = Psych.domain_types
2829
@class_loader = class_loader
2930
@symbolize_names = symbolize_names
@@ -48,7 +49,7 @@ def accept target
4849
end
4950

5051
def deserialize o
51-
if klass = resolve_class(Psych.load_tags[o.tag])
52+
if klass = resolve_class(@load_tags[o.tag])
5253
instance = klass.allocate
5354

5455
if instance.respond_to?(:init_with)
@@ -128,7 +129,7 @@ def visit_Psych_Nodes_Scalar o
128129
end
129130

130131
def visit_Psych_Nodes_Sequence o
131-
if klass = resolve_class(Psych.load_tags[o.tag])
132+
if klass = resolve_class(@load_tags[o.tag])
132133
instance = klass.allocate
133134

134135
if instance.respond_to?(:init_with)
@@ -160,8 +161,8 @@ def visit_Psych_Nodes_Sequence o
160161
end
161162

162163
def visit_Psych_Nodes_Mapping o
163-
if Psych.load_tags[o.tag]
164-
return revive(resolve_class(Psych.load_tags[o.tag]), o)
164+
if @load_tags[o.tag]
165+
return revive(resolve_class(@load_tags[o.tag]), o)
165166
end
166167
return revive_hash(register(o, {}), o) unless o.tag
167168

@@ -326,6 +327,7 @@ def visit_Psych_Nodes_Alias o
326327
end
327328

328329
private
330+
329331
def register node, object
330332
@st[node.anchor] = object if node.anchor
331333
object

0 commit comments

Comments
 (0)