Skip to content

Commit

Permalink
Cache access to Psych.load_tags in Visitor::ToRuby
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Jan 30, 2021
1 parent 0abce07 commit 58223f0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/psych/visitors/to_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def initialize ss, class_loader, symbolize_names: false, freeze: false
super()
@st = {}
@ss = ss
@load_tags = Psych.load_tags
@domain_types = Psych.domain_types
@class_loader = class_loader
@symbolize_names = symbolize_names
Expand All @@ -48,7 +49,7 @@ def accept target
end

def deserialize o
if klass = resolve_class(Psych.load_tags[o.tag])
if klass = resolve_class(@load_tags[o.tag])
instance = klass.allocate

if instance.respond_to?(:init_with)
Expand Down Expand Up @@ -128,7 +129,7 @@ def visit_Psych_Nodes_Scalar o
end

def visit_Psych_Nodes_Sequence o
if klass = resolve_class(Psych.load_tags[o.tag])
if klass = resolve_class(@load_tags[o.tag])
instance = klass.allocate

if instance.respond_to?(:init_with)
Expand Down Expand Up @@ -160,8 +161,8 @@ def visit_Psych_Nodes_Sequence o
end

def visit_Psych_Nodes_Mapping o
if Psych.load_tags[o.tag]
return revive(resolve_class(Psych.load_tags[o.tag]), o)
if @load_tags[o.tag]
return revive(resolve_class(@load_tags[o.tag]), o)
end
return revive_hash(register(o, {}), o) unless o.tag

Expand Down Expand Up @@ -326,6 +327,7 @@ def visit_Psych_Nodes_Alias o
end

private

def register node, object
@st[node.anchor] = object if node.anchor
object
Expand Down

0 comments on commit 58223f0

Please sign in to comment.